home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / Python 1.3 / source code / Doc / libfuncs.tex < prev    next >
LaTeX Document  |  1995-12-17  |  20.7 KB  |  [TEXT/R*ch]

open in: MacOS 8.1     |     Win98     |     DOS

browse contents    |     view JSON data     |     view as text


This file was processed as: LaTeX Document (document/latex).

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert LaTeX Document (document/latex) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file LaTeX document text default
99% file LaTeX document, ASCII text, with CR line terminators default
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/281 LaTeX (Subdocument) default
100% detectItEasy Format: plain text[CR] default (weak)


id metadata
keyvalue
macFileType[TEXT]
macFileCreator[R*ch]



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 5c 73 65 63 74 69 6f 6e | 7b 42 75 69 6c 74 2d 69 |\section|{Built-i|
|00000010| 6e 20 46 75 6e 63 74 69 | 6f 6e 73 7d 0d 0d 54 68 |n Functi|ons}..Th|
|00000020| 65 20 50 79 74 68 6f 6e | 20 69 6e 74 65 72 70 72 |e Python| interpr|
|00000030| 65 74 65 72 20 68 61 73 | 20 61 20 6e 75 6d 62 65 |eter has| a numbe|
|00000040| 72 20 6f 66 20 66 75 6e | 63 74 69 6f 6e 73 20 62 |r of fun|ctions b|
|00000050| 75 69 6c 74 20 69 6e 74 | 6f 20 69 74 20 74 68 61 |uilt int|o it tha|
|00000060| 74 0d 61 72 65 20 61 6c | 77 61 79 73 20 61 76 61 |t.are al|ways ava|
|00000070| 69 6c 61 62 6c 65 2e 20 | 20 54 68 65 79 20 61 72 |ilable. | They ar|
|00000080| 65 20 6c 69 73 74 65 64 | 20 68 65 72 65 20 69 6e |e listed| here in|
|00000090| 20 61 6c 70 68 61 62 65 | 74 69 63 61 6c 20 6f 72 | alphabe|tical or|
|000000a0| 64 65 72 2e 0d 0d 0d 5c | 72 65 6e 65 77 63 6f 6d |der....\|renewcom|
|000000b0| 6d 61 6e 64 7b 5c 69 6e | 64 65 78 73 75 62 69 74 |mand{\in|dexsubit|
|000000c0| 65 6d 7d 7b 28 62 75 69 | 6c 74 2d 69 6e 20 66 75 |em}{(bui|lt-in fu|
|000000d0| 6e 63 74 69 6f 6e 29 7d | 0d 5c 62 65 67 69 6e 7b |nction)}|.\begin{|
|000000e0| 66 75 6e 63 64 65 73 63 | 7d 7b 61 62 73 7d 7b 78 |funcdesc|}{abs}{x|
|000000f0| 7d 0d 20 20 52 65 74 75 | 72 6e 20 74 68 65 20 61 |}. Retu|rn the a|
|00000100| 62 73 6f 6c 75 74 65 20 | 76 61 6c 75 65 20 6f 66 |bsolute |value of|
|00000110| 20 61 20 6e 75 6d 62 65 | 72 2e 20 20 54 68 65 20 | a numbe|r. The |
|00000120| 61 72 67 75 6d 65 6e 74 | 20 6d 61 79 20 62 65 20 |argument| may be |
|00000130| 61 20 70 6c 61 69 6e 0d | 20 20 6f 72 20 6c 6f 6e |a plain.| or lon|
|00000140| 67 20 69 6e 74 65 67 65 | 72 20 6f 72 20 61 20 66 |g intege|r or a f|
|00000150| 6c 6f 61 74 69 6e 67 20 | 70 6f 69 6e 74 20 6e 75 |loating |point nu|
|00000160| 6d 62 65 72 2e 0d 5c 65 | 6e 64 7b 66 75 6e 63 64 |mber..\e|nd{funcd|
|00000170| 65 73 63 7d 0d 0d 5c 62 | 65 67 69 6e 7b 66 75 6e |esc}..\b|egin{fun|
|00000180| 63 64 65 73 63 7d 7b 61 | 70 70 6c 79 7d 7b 66 75 |cdesc}{a|pply}{fu|
|00000190| 6e 63 74 69 6f 6e 5c 2c | 20 61 72 67 73 5c 6f 70 |nction\,| args\op|
|000001a0| 74 69 6f 6e 61 6c 7b 2c | 20 6b 65 79 77 6f 72 64 |tional{,| keyword|
|000001b0| 73 7d 7d 0d 54 68 65 20 | 5c 76 61 72 7b 66 75 6e |s}}.The |\var{fun|
|000001c0| 63 74 69 6f 6e 7d 20 61 | 72 67 75 6d 65 6e 74 20 |ction} a|rgument |
|000001d0| 6d 75 73 74 20 62 65 20 | 61 20 63 61 6c 6c 61 62 |must be |a callab|
|000001e0| 6c 65 20 6f 62 6a 65 63 | 74 20 28 61 20 75 73 65 |le objec|t (a use|
|000001f0| 72 2d 64 65 66 69 6e 65 | 64 20 6f 72 0d 62 75 69 |r-define|d or.bui|
|00000200| 6c 74 2d 69 6e 20 66 75 | 6e 63 74 69 6f 6e 20 6f |lt-in fu|nction o|
|00000210| 72 20 6d 65 74 68 6f 64 | 2c 20 6f 72 20 61 20 63 |r method|, or a c|
|00000220| 6c 61 73 73 20 6f 62 6a | 65 63 74 29 20 61 6e 64 |lass obj|ect) and|
|00000230| 20 74 68 65 20 5c 76 61 | 72 7b 61 72 67 73 7d 0d | the \va|r{args}.|
|00000240| 61 72 67 75 6d 65 6e 74 | 20 6d 75 73 74 20 62 65 |argument| must be|
|00000250| 20 61 20 74 75 70 6c 65 | 2e 20 20 54 68 65 20 5c | a tuple|. The \|
|00000260| 76 61 72 7b 66 75 6e 63 | 74 69 6f 6e 7d 20 69 73 |var{func|tion} is|
|00000270| 20 63 61 6c 6c 65 64 20 | 77 69 74 68 0d 5c 76 61 | called |with.\va|
|00000280| 72 7b 61 72 67 73 7d 20 | 61 73 20 61 72 67 75 6d |r{args} |as argum|
|00000290| 65 6e 74 20 6c 69 73 74 | 3b 20 74 68 65 20 6e 75 |ent list|; the nu|
|000002a0| 6d 62 65 72 20 6f 66 20 | 61 72 67 75 6d 65 6e 74 |mber of |argument|
|000002b0| 73 20 69 73 20 74 68 65 | 20 74 68 65 20 6c 65 6e |s is the| the len|
|000002c0| 67 74 68 0d 6f 66 20 74 | 68 65 20 74 75 70 6c 65 |gth.of t|he tuple|
|000002d0| 2e 20 20 28 54 68 69 73 | 20 69 73 20 64 69 66 66 |. (This| is diff|
|000002e0| 65 72 65 6e 74 20 66 72 | 6f 6d 20 6a 75 73 74 20 |erent fr|om just |
|000002f0| 63 61 6c 6c 69 6e 67 0d | 5c 63 6f 64 65 7b 5c 76 |calling.|\code{\v|
|00000300| 61 72 7b 66 75 6e 63 7d | 28 5c 76 61 72 7b 61 72 |ar{func}|(\var{ar|
|00000310| 67 73 7d 29 7d 2c 20 73 | 69 6e 63 65 20 69 6e 20 |gs})}, s|ince in |
|00000320| 74 68 61 74 20 63 61 73 | 65 20 74 68 65 72 65 20 |that cas|e there |
|00000330| 69 73 20 61 6c 77 61 79 | 73 0d 65 78 61 63 74 6c |is alway|s.exactl|
|00000340| 79 20 6f 6e 65 20 61 72 | 67 75 6d 65 6e 74 2e 29 |y one ar|gument.)|
|00000350| 0d 49 66 20 74 68 65 20 | 6f 70 74 69 6f 6e 61 6c |.If the |optional|
|00000360| 20 5c 76 61 72 7b 6b 65 | 79 77 6f 72 64 73 7d 20 | \var{ke|ywords} |
|00000370| 61 72 67 75 6d 65 6e 74 | 20 69 73 20 70 72 65 73 |argument| is pres|
|00000380| 65 6e 74 2c 20 69 74 20 | 6d 75 73 74 20 62 65 20 |ent, it |must be |
|00000390| 61 0d 64 69 63 74 69 6f | 6e 61 72 79 20 77 68 6f |a.dictio|nary who|
|000003a0| 73 65 20 6b 65 79 73 20 | 61 72 65 20 73 74 72 69 |se keys |are stri|
|000003b0| 6e 67 73 2e 20 20 49 74 | 20 73 70 65 63 69 66 69 |ngs. It| specifi|
|000003c0| 65 73 20 6b 65 79 77 6f | 72 64 20 61 72 67 75 6d |es keywo|rd argum|
|000003d0| 65 6e 74 73 20 74 6f 0d | 62 65 20 61 64 64 65 64 |ents to.|be added|
|000003e0| 20 74 6f 20 74 68 65 20 | 65 6e 64 20 6f 66 20 74 | to the |end of t|
|000003f0| 68 65 20 74 68 65 20 61 | 72 67 75 6d 65 6e 74 20 |he the a|rgument |
|00000400| 6c 69 73 74 2e 0d 5c 65 | 6e 64 7b 66 75 6e 63 64 |list..\e|nd{funcd|
|00000410| 65 73 63 7d 0d 0d 5c 62 | 65 67 69 6e 7b 66 75 6e |esc}..\b|egin{fun|
|00000420| 63 64 65 73 63 7d 7b 63 | 68 72 7d 7b 69 7d 0d 20 |cdesc}{c|hr}{i}. |
|00000430| 20 52 65 74 75 72 6e 20 | 61 20 73 74 72 69 6e 67 | Return |a string|
|00000440| 20 6f 66 20 6f 6e 65 20 | 63 68 61 72 61 63 74 65 | of one |characte|
|00000450| 72 20 77 68 6f 73 65 20 | 5c 41 53 43 49 49 7b 7d |r whose |\ASCII{}|
|00000460| 20 63 6f 64 65 20 69 73 | 20 74 68 65 20 69 6e 74 | code is| the int|
|00000470| 65 67 65 72 0d 20 20 5c | 76 61 72 7b 69 7d 2c 20 |eger. \|var{i}, |
|00000480| 65 2e 67 2e 2c 20 5c 63 | 6f 64 65 7b 63 68 72 28 |e.g., \c|ode{chr(|
|00000490| 39 37 29 7d 20 72 65 74 | 75 72 6e 73 20 74 68 65 |97)} ret|urns the|
|000004a0| 20 73 74 72 69 6e 67 20 | 5c 63 6f 64 65 7b 27 61 | string |\code{'a|
|000004b0| 27 7d 2e 20 20 54 68 69 | 73 20 69 73 20 74 68 65 |'}. Thi|s is the|
|000004c0| 0d 20 20 69 6e 76 65 72 | 73 65 20 6f 66 20 5c 63 |. inver|se of \c|
|000004d0| 6f 64 65 7b 6f 72 64 28 | 29 7d 2e 20 20 54 68 65 |ode{ord(|)}. The|
|000004e0| 20 61 72 67 75 6d 65 6e | 74 20 6d 75 73 74 20 62 | argumen|t must b|
|000004f0| 65 20 69 6e 20 74 68 65 | 20 72 61 6e 67 65 20 5b |e in the| range [|
|00000500| 30 2e 2e 32 35 35 5d 2c | 0d 20 20 69 6e 63 6c 75 |0..255],|. inclu|
|00000510| 73 69 76 65 2e 0d 5c 65 | 6e 64 7b 66 75 6e 63 64 |sive..\e|nd{funcd|
|00000520| 65 73 63 7d 0d 0d 5c 62 | 65 67 69 6e 7b 66 75 6e |esc}..\b|egin{fun|
|00000530| 63 64 65 73 63 7d 7b 63 | 6d 70 7d 7b 78 5c 2c 20 |cdesc}{c|mp}{x\, |
|00000540| 79 7d 0d 20 20 43 6f 6d | 70 61 72 65 20 74 68 65 |y}. Com|pare the|
|00000550| 20 74 77 6f 20 6f 62 6a | 65 63 74 73 20 5c 76 61 | two obj|ects \va|
|00000560| 72 7b 78 7d 20 61 6e 64 | 20 5c 76 61 72 7b 79 7d |r{x} and| \var{y}|
|00000570| 20 61 6e 64 20 72 65 74 | 75 72 6e 20 61 6e 20 69 | and ret|urn an i|
|00000580| 6e 74 65 67 65 72 0d 20 | 20 61 63 63 6f 72 64 69 |nteger. | accordi|
|00000590| 6e 67 20 74 6f 20 74 68 | 65 20 6f 75 74 63 6f 6d |ng to th|e outcom|
|000005a0| 65 2e 20 20 54 68 65 20 | 72 65 74 75 72 6e 20 76 |e. The |return v|
|000005b0| 61 6c 75 65 20 69 73 20 | 6e 65 67 61 74 69 76 65 |alue is |negative|
|000005c0| 20 69 66 20 5c 63 6f 64 | 65 7b 5c 76 61 72 7b 78 | if \cod|e{\var{x|
|000005d0| 7d 0d 20 20 3c 20 5c 76 | 61 72 7b 79 7d 7d 2c 20 |}. < \v|ar{y}}, |
|000005e0| 7a 65 72 6f 20 69 66 20 | 5c 63 6f 64 65 7b 5c 76 |zero if |\code{\v|
|000005f0| 61 72 7b 78 7d 20 3d 3d | 20 5c 76 61 72 7b 79 7d |ar{x} ==| \var{y}|
|00000600| 7d 20 61 6e 64 20 73 74 | 72 69 63 74 6c 79 20 70 |} and st|rictly p|
|00000610| 6f 73 69 74 69 76 65 20 | 69 66 0d 20 20 5c 63 6f |ositive |if. \co|
|00000620| 64 65 7b 5c 76 61 72 7b | 78 7d 20 3e 20 5c 76 61 |de{\var{|x} > \va|
|00000630| 72 7b 79 7d 7d 2e 0d 5c | 65 6e 64 7b 66 75 6e 63 |r{y}}..\|end{func|
|00000640| 64 65 73 63 7d 0d 0d 5c | 62 65 67 69 6e 7b 66 75 |desc}..\|begin{fu|
|00000650| 6e 63 64 65 73 63 7d 7b | 63 6f 65 72 63 65 7d 7b |ncdesc}{|coerce}{|
|00000660| 78 5c 2c 20 79 7d 0d 20 | 20 52 65 74 75 72 6e 20 |x\, y}. | Return |
|00000670| 61 20 74 75 70 6c 65 20 | 63 6f 6e 73 69 73 74 69 |a tuple |consisti|
|00000680| 6e 67 20 6f 66 20 74 68 | 65 20 74 77 6f 20 6e 75 |ng of th|e two nu|
|00000690| 6d 65 72 69 63 20 61 72 | 67 75 6d 65 6e 74 73 20 |meric ar|guments |
|000006a0| 63 6f 6e 76 65 72 74 65 | 64 20 74 6f 0d 20 20 61 |converte|d to. a|
|000006b0| 20 63 6f 6d 6d 6f 6e 20 | 74 79 70 65 2c 20 75 73 | common |type, us|
|000006c0| 69 6e 67 20 74 68 65 20 | 73 61 6d 65 20 72 75 6c |ing the |same rul|
|000006d0| 65 73 20 61 73 20 75 73 | 65 64 20 62 79 20 61 72 |es as us|ed by ar|
|000006e0| 69 74 68 6d 65 74 69 63 | 0d 20 20 6f 70 65 72 61 |ithmetic|. opera|
|000006f0| 74 69 6f 6e 73 2e 0d 5c | 65 6e 64 7b 66 75 6e 63 |tions..\|end{func|
|00000700| 64 65 73 63 7d 0d 0d 5c | 62 65 67 69 6e 7b 66 75 |desc}..\|begin{fu|
|00000710| 6e 63 64 65 73 63 7d 7b | 63 6f 6d 70 69 6c 65 7d |ncdesc}{|compile}|
|00000720| 7b 73 74 72 69 6e 67 5c | 2c 20 66 69 6c 65 6e 61 |{string\|, filena|
|00000730| 6d 65 5c 2c 20 6b 69 6e | 64 7d 0d 20 20 43 6f 6d |me\, kin|d}. Com|
|00000740| 70 69 6c 65 20 74 68 65 | 20 5c 76 61 72 7b 73 74 |pile the| \var{st|
|00000750| 72 69 6e 67 7d 20 69 6e | 74 6f 20 61 20 63 6f 64 |ring} in|to a cod|
|00000760| 65 20 6f 62 6a 65 63 74 | 2e 20 20 43 6f 64 65 20 |e object|. Code |
|00000770| 6f 62 6a 65 63 74 73 20 | 63 61 6e 20 62 65 0d 20 |objects |can be. |
|00000780| 20 65 78 65 63 75 74 65 | 64 20 62 79 20 61 6e 20 | execute|d by an |
|00000790| 5c 63 6f 64 65 7b 65 78 | 65 63 7d 20 73 74 61 74 |\code{ex|ec} stat|
|000007a0| 65 6d 65 6e 74 20 6f 72 | 20 65 76 61 6c 75 61 74 |ement or| evaluat|
|000007b0| 65 64 20 62 79 20 61 20 | 63 61 6c 6c 20 74 6f 0d |ed by a |call to.|
|000007c0| 20 20 5c 63 6f 64 65 7b | 65 76 61 6c 28 29 7d 2e | \code{|eval()}.|
|000007d0| 20 20 54 68 65 20 5c 76 | 61 72 7b 66 69 6c 65 6e | The \v|ar{filen|
|000007e0| 61 6d 65 7d 20 61 72 67 | 75 6d 65 6e 74 20 73 68 |ame} arg|ument sh|
|000007f0| 6f 75 6c 64 0d 20 20 67 | 69 76 65 20 74 68 65 20 |ould. g|ive the |
|00000800| 66 69 6c 65 20 66 72 6f | 6d 20 77 68 69 63 68 20 |file fro|m which |
|00000810| 74 68 65 20 63 6f 64 65 | 20 77 61 73 20 72 65 61 |the code| was rea|
|00000820| 64 3b 20 70 61 73 73 20 | 65 2e 67 2e 20 5c 63 6f |d; pass |e.g. \co|
|00000830| 64 65 7b 27 3c 73 74 72 | 69 6e 67 3e 27 7d 0d 20 |de{'<str|ing>'}. |
|00000840| 20 69 66 20 69 74 20 77 | 61 73 6e 27 74 20 72 65 | if it w|asn't re|
|00000850| 61 64 20 66 72 6f 6d 20 | 61 20 66 69 6c 65 2e 20 |ad from |a file. |
|00000860| 20 54 68 65 20 5c 76 61 | 72 7b 6b 69 6e 64 7d 20 | The \va|r{kind} |
|00000870| 61 72 67 75 6d 65 6e 74 | 20 73 70 65 63 69 66 69 |argument| specifi|
|00000880| 65 73 0d 20 20 77 68 61 | 74 20 6b 69 6e 64 20 6f |es. wha|t kind o|
|00000890| 66 20 63 6f 64 65 20 6d | 75 73 74 20 62 65 20 63 |f code m|ust be c|
|000008a0| 6f 6d 70 69 6c 65 64 3b | 20 69 74 20 63 61 6e 20 |ompiled;| it can |
|000008b0| 62 65 20 5c 63 6f 64 65 | 7b 27 65 78 65 63 27 7d |be \code|{'exec'}|
|000008c0| 20 69 66 0d 20 20 5c 76 | 61 72 7b 73 74 72 69 6e | if. \v|ar{strin|
|000008d0| 67 7d 20 63 6f 6e 73 69 | 73 74 73 20 6f 66 20 61 |g} consi|sts of a|
|000008e0| 20 73 65 71 75 65 6e 63 | 65 20 6f 66 20 73 74 61 | sequenc|e of sta|
|000008f0| 74 65 6d 65 6e 74 73 2c | 20 5c 63 6f 64 65 7b 27 |tements,| \code{'|
|00000900| 65 76 61 6c 27 7d 0d 20 | 20 69 66 20 69 74 20 63 |eval'}. | if it c|
|00000910| 6f 6e 73 69 73 74 73 20 | 6f 66 20 61 20 73 69 6e |onsists |of a sin|
|00000920| 67 6c 65 20 65 78 70 72 | 65 73 73 69 6f 6e 2c 20 |gle expr|ession, |
|00000930| 6f 72 20 5c 63 6f 64 65 | 7b 27 73 69 6e 67 6c 65 |or \code|{'single|
|00000940| 27 7d 20 69 66 0d 20 20 | 69 74 20 63 6f 6e 73 69 |'} if. |it consi|
|00000950| 73 74 73 20 6f 66 20 61 | 20 73 69 6e 67 6c 65 20 |sts of a| single |
|00000960| 69 6e 74 65 72 61 63 74 | 69 76 65 20 73 74 61 74 |interact|ive stat|
|00000970| 65 6d 65 6e 74 20 28 69 | 6e 20 74 68 65 20 6c 61 |ement (i|n the la|
|00000980| 74 74 65 72 20 63 61 73 | 65 2c 0d 20 20 65 78 70 |tter cas|e,. exp|
|00000990| 72 65 73 73 69 6f 6e 20 | 73 74 61 74 65 6d 65 6e |ression |statemen|
|000009a0| 74 73 20 74 68 61 74 20 | 65 76 61 6c 75 61 74 65 |ts that |evaluate|
|000009b0| 20 74 6f 20 73 6f 6d 65 | 74 68 69 6e 67 20 65 6c | to some|thing el|
|000009c0| 73 65 20 74 68 61 6e 0d | 20 20 5c 63 6f 64 65 7b |se than.| \code{|
|000009d0| 4e 6f 6e 65 7d 20 77 69 | 6c 6c 20 70 72 69 6e 74 |None} wi|ll print|
|000009e0| 65 64 29 2e 0d 5c 65 6e | 64 7b 66 75 6e 63 64 65 |ed)..\en|d{funcde|
|000009f0| 73 63 7d 0d 0d 5c 62 65 | 67 69 6e 7b 66 75 6e 63 |sc}..\be|gin{func|
|00000a00| 64 65 73 63 7d 7b 64 65 | 6c 61 74 74 72 7d 7b 6f |desc}{de|lattr}{o|
|00000a10| 62 6a 65 63 74 5c 2c 20 | 6e 61 6d 65 7d 0d 20 20 |bject\, |name}. |
|00000a20| 54 68 69 73 20 69 73 20 | 61 20 72 65 6c 61 74 69 |This is |a relati|
|00000a30| 76 65 20 6f 66 20 5c 63 | 6f 64 65 7b 73 65 74 61 |ve of \c|ode{seta|
|00000a40| 74 74 72 7d 2e 20 20 54 | 68 65 20 61 72 67 75 6d |ttr}. T|he argum|
|00000a50| 65 6e 74 73 20 61 72 65 | 20 61 6e 0d 20 20 6f 62 |ents are| an. ob|
|00000a60| 6a 65 63 74 20 61 6e 64 | 20 61 20 73 74 72 69 6e |ject and| a strin|
|00000a70| 67 2e 20 20 54 68 65 20 | 73 74 72 69 6e 67 20 6d |g. The |string m|
|00000a80| 75 73 74 20 62 65 20 74 | 68 65 20 6e 61 6d 65 0d |ust be t|he name.|
|00000a90| 20 20 6f 66 20 6f 6e 65 | 20 6f 66 20 74 68 65 20 | of one| of the |
|00000aa0| 6f 62 6a 65 63 74 27 73 | 20 61 74 74 72 69 62 75 |object's| attribu|
|00000ab0| 74 65 73 2e 20 20 54 68 | 65 20 66 75 6e 63 74 69 |tes. Th|e functi|
|00000ac0| 6f 6e 20 64 65 6c 65 74 | 65 73 0d 20 20 74 68 65 |on delet|es. the|
|00000ad0| 20 6e 61 6d 65 64 20 61 | 74 74 72 69 62 75 74 65 | named a|ttribute|
|00000ae0| 2c 20 70 72 6f 76 69 64 | 65 64 20 74 68 65 20 6f |, provid|ed the o|
|00000af0| 62 6a 65 63 74 20 61 6c | 6c 6f 77 73 20 69 74 2e |bject al|lows it.|
|00000b00| 20 20 46 6f 72 20 65 78 | 61 6d 70 6c 65 2c 0d 20 | For ex|ample,. |
|00000b10| 20 5c 63 6f 64 65 7b 64 | 65 6c 61 74 74 72 28 5c | \code{d|elattr(\|
|00000b20| 76 61 72 7b 78 7d 2c 20 | 27 5c 76 61 72 7b 66 6f |var{x}, |'\var{fo|
|00000b30| 6f 62 61 72 7d 27 29 7d | 20 69 73 20 65 71 75 69 |obar}')}| is equi|
|00000b40| 76 61 6c 65 6e 74 20 74 | 6f 0d 20 20 5c 63 6f 64 |valent t|o. \cod|
|00000b50| 65 7b 64 65 6c 20 5c 76 | 61 72 7b 78 7d 2e 5c 76 |e{del \v|ar{x}.\v|
|00000b60| 61 72 7b 66 6f 6f 62 61 | 72 7d 7d 2e 0d 5c 65 6e |ar{fooba|r}}..\en|
|00000b70| 64 7b 66 75 6e 63 64 65 | 73 63 7d 0d 0d 5c 62 65 |d{funcde|sc}..\be|
|00000b80| 67 69 6e 7b 66 75 6e 63 | 64 65 73 63 7d 7b 64 69 |gin{func|desc}{di|
|00000b90| 72 7d 7b 7d 0d 20 20 57 | 69 74 68 6f 75 74 20 61 |r}{}. W|ithout a|
|00000ba0| 72 67 75 6d 65 6e 74 73 | 2c 20 72 65 74 75 72 6e |rguments|, return|
|00000bb0| 20 74 68 65 20 6c 69 73 | 74 20 6f 66 20 6e 61 6d | the lis|t of nam|
|00000bc0| 65 73 20 69 6e 20 74 68 | 65 20 63 75 72 72 65 6e |es in th|e curren|
|00000bd0| 74 20 6c 6f 63 61 6c 0d | 20 20 73 79 6d 62 6f 6c |t local.| symbol|
|00000be0| 20 74 61 62 6c 65 2e 20 | 20 57 69 74 68 20 61 20 | table. | With a |
|00000bf0| 6d 6f 64 75 6c 65 2c 20 | 63 6c 61 73 73 20 6f 72 |module, |class or|
|00000c00| 20 63 6c 61 73 73 20 69 | 6e 73 74 61 6e 63 65 20 | class i|nstance |
|00000c10| 6f 62 6a 65 63 74 20 61 | 73 0d 20 20 61 72 67 75 |object a|s. argu|
|00000c20| 6d 65 6e 74 20 28 6f 72 | 20 61 6e 79 74 68 69 6e |ment (or| anythin|
|00000c30| 67 20 65 6c 73 65 20 74 | 68 61 74 20 68 61 73 20 |g else t|hat has |
|00000c40| 61 20 5c 63 6f 64 65 7b | 5f 5f 64 69 63 74 5f 5f |a \code{|__dict__|
|00000c50| 7d 20 61 74 74 72 69 62 | 75 74 65 29 2c 0d 20 20 |} attrib|ute),. |
|00000c60| 72 65 74 75 72 6e 73 20 | 74 68 65 20 6c 69 73 74 |returns |the list|
|00000c70| 20 6f 66 20 6e 61 6d 65 | 73 20 69 6e 20 74 68 61 | of name|s in tha|
|00000c80| 74 20 6f 62 6a 65 63 74 | 27 73 20 61 74 74 72 69 |t object|'s attri|
|00000c90| 62 75 74 65 20 64 69 63 | 74 69 6f 6e 61 72 79 2e |bute dic|tionary.|
|00000ca0| 0d 20 20 54 68 65 20 72 | 65 73 75 6c 74 69 6e 67 |. The r|esulting|
|00000cb0| 20 6c 69 73 74 20 69 73 | 20 73 6f 72 74 65 64 2e | list is| sorted.|
|00000cc0| 20 20 46 6f 72 20 65 78 | 61 6d 70 6c 65 3a 0d 0d | For ex|ample:..|
|00000cd0| 5c 62 63 6f 64 65 5c 62 | 65 67 69 6e 7b 76 65 72 |\bcode\b|egin{ver|
|00000ce0| 62 61 74 69 6d 7d 0d 3e | 3e 3e 20 69 6d 70 6f 72 |batim}.>|>> impor|
|00000cf0| 74 20 73 79 73 0d 3e 3e | 3e 20 64 69 72 28 29 0d |t sys.>>|> dir().|
|00000d00| 5b 27 73 79 73 27 5d 0d | 3e 3e 3e 20 64 69 72 28 |['sys'].|>>> dir(|
|00000d10| 73 79 73 29 0d 5b 27 61 | 72 67 76 27 2c 20 27 65 |sys).['a|rgv', 'e|
|00000d20| 78 69 74 27 2c 20 27 6d | 6f 64 75 6c 65 73 27 2c |xit', 'm|odules',|
|00000d30| 20 27 70 61 74 68 27 2c | 20 27 73 74 64 65 72 72 | 'path',| 'stderr|
|00000d40| 27 2c 20 27 73 74 64 69 | 6e 27 2c 20 27 73 74 64 |', 'stdi|n', 'std|
|00000d50| 6f 75 74 27 5d 0d 3e 3e | 3e 20 0d 5c 65 6e 64 7b |out'].>>|> .\end{|
|00000d60| 76 65 72 62 61 74 69 6d | 7d 5c 65 63 6f 64 65 0d |verbatim|}\ecode.|
|00000d70| 5c 65 6e 64 7b 66 75 6e | 63 64 65 73 63 7d 0d 0d |\end{fun|cdesc}..|
|00000d80| 5c 62 65 67 69 6e 7b 66 | 75 6e 63 64 65 73 63 7d |\begin{f|uncdesc}|
|00000d90| 7b 64 69 76 6d 6f 64 7d | 7b 61 5c 2c 20 62 7d 0d |{divmod}|{a\, b}.|
|00000da0| 20 20 54 61 6b 65 20 74 | 77 6f 20 6e 75 6d 62 65 | Take t|wo numbe|
|00000db0| 72 73 20 61 73 20 61 72 | 67 75 6d 65 6e 74 73 20 |rs as ar|guments |
|00000dc0| 61 6e 64 20 72 65 74 75 | 72 6e 20 61 20 70 61 69 |and retu|rn a pai|
|00000dd0| 72 20 6f 66 20 69 6e 74 | 65 67 65 72 73 0d 20 20 |r of int|egers. |
|00000de0| 63 6f 6e 73 69 73 74 69 | 6e 67 20 6f 66 20 74 68 |consisti|ng of th|
|00000df0| 65 69 72 20 69 6e 74 65 | 67 65 72 20 71 75 6f 74 |eir inte|ger quot|
|00000e00| 69 65 6e 74 20 61 6e 64 | 20 72 65 6d 61 69 6e 64 |ient and| remaind|
|00000e10| 65 72 2e 20 20 57 69 74 | 68 20 6d 69 78 65 64 0d |er. Wit|h mixed.|
|00000e20| 20 20 6f 70 65 72 61 6e | 64 20 74 79 70 65 73 2c | operan|d types,|
|00000e30| 20 74 68 65 20 72 75 6c | 65 73 20 66 6f 72 20 62 | the rul|es for b|
|00000e40| 69 6e 61 72 79 20 61 72 | 69 74 68 6d 65 74 69 63 |inary ar|ithmetic|
|00000e50| 20 6f 70 65 72 61 74 6f | 72 73 20 61 70 70 6c 79 | operato|rs apply|
|00000e60| 2e 20 20 46 6f 72 0d 20 | 20 70 6c 61 69 6e 20 61 |. For. | plain a|
|00000e70| 6e 64 20 6c 6f 6e 67 20 | 69 6e 74 65 67 65 72 73 |nd long |integers|
|00000e80| 2c 20 74 68 65 20 72 65 | 73 75 6c 74 20 69 73 20 |, the re|sult is |
|00000e90| 74 68 65 20 73 61 6d 65 | 20 61 73 0d 20 20 5c 63 |the same| as. \c|
|00000ea0| 6f 64 65 7b 28 5c 76 61 | 72 7b 61 7d 20 2f 20 5c |ode{(\va|r{a} / \|
|00000eb0| 76 61 72 7b 62 7d 2c 20 | 5c 76 61 72 7b 61 7d 20 |var{b}, |\var{a} |
|00000ec0| 5c 25 7b 7d 20 5c 76 61 | 72 7b 62 7d 29 7d 2e 0d |\%{} \va|r{b})}..|
|00000ed0| 20 20 46 6f 72 20 66 6c | 6f 61 74 69 6e 67 20 70 | For fl|oating p|
|00000ee0| 6f 69 6e 74 20 6e 75 6d | 62 65 72 73 20 74 68 65 |oint num|bers the|
|00000ef0| 20 72 65 73 75 6c 74 20 | 69 73 20 74 68 65 20 73 | result |is the s|
|00000f00| 61 6d 65 20 61 73 0d 20 | 20 5c 63 6f 64 65 7b 28 |ame as. | \code{(|
|00000f10| 6d 61 74 68 2e 66 6c 6f | 6f 72 28 5c 76 61 72 7b |math.flo|or(\var{|
|00000f20| 61 7d 20 2f 20 5c 76 61 | 72 7b 62 7d 29 2c 20 5c |a} / \va|r{b}), \|
|00000f30| 76 61 72 7b 61 7d 20 5c | 25 7b 7d 20 5c 76 61 72 |var{a} \|%{} \var|
|00000f40| 7b 62 7d 29 7d 2e 0d 5c | 65 6e 64 7b 66 75 6e 63 |{b})}..\|end{func|
|00000f50| 64 65 73 63 7d 0d 0d 5c | 62 65 67 69 6e 7b 66 75 |desc}..\|begin{fu|
|00000f60| 6e 63 64 65 73 63 7d 7b | 65 76 61 6c 7d 7b 65 78 |ncdesc}{|eval}{ex|
|00000f70| 70 72 65 73 73 69 6f 6e | 5c 6f 70 74 69 6f 6e 61 |pression|\optiona|
|00000f80| 6c 7b 5c 2c 20 67 6c 6f | 62 61 6c 73 5c 6f 70 74 |l{\, glo|bals\opt|
|00000f90| 69 6f 6e 61 6c 7b 5c 2c | 20 6c 6f 63 61 6c 73 7d |ional{\,| locals}|
|00000fa0| 7d 7d 0d 20 20 54 68 65 | 20 61 72 67 75 6d 65 6e |}}. The| argumen|
|00000fb0| 74 73 20 61 72 65 20 61 | 20 73 74 72 69 6e 67 20 |ts are a| string |
|00000fc0| 61 6e 64 20 74 77 6f 20 | 6f 70 74 69 6f 6e 61 6c |and two |optional|
|00000fd0| 20 64 69 63 74 69 6f 6e | 61 72 69 65 73 2e 20 20 | diction|aries. |
|00000fe0| 54 68 65 0d 20 20 5c 76 | 61 72 7b 65 78 70 72 65 |The. \v|ar{expre|
|00000ff0| 73 73 69 6f 6e 7d 20 61 | 72 67 75 6d 65 6e 74 20 |ssion} a|rgument |
|00001000| 69 73 20 70 61 72 73 65 | 64 20 61 6e 64 20 65 76 |is parse|d and ev|
|00001010| 61 6c 75 61 74 65 64 20 | 61 73 20 61 20 50 79 74 |aluated |as a Pyt|
|00001020| 68 6f 6e 0d 20 20 65 78 | 70 72 65 73 73 69 6f 6e |hon. ex|pression|
|00001030| 20 28 74 65 63 68 6e 69 | 63 61 6c 6c 79 20 73 70 | (techni|cally sp|
|00001040| 65 61 6b 69 6e 67 2c 20 | 61 20 63 6f 6e 64 69 74 |eaking, |a condit|
|00001050| 69 6f 6e 20 6c 69 73 74 | 29 20 75 73 69 6e 67 20 |ion list|) using |
|00001060| 74 68 65 0d 20 20 5c 76 | 61 72 7b 67 6c 6f 62 61 |the. \v|ar{globa|
|00001070| 6c 73 7d 20 61 6e 64 20 | 5c 76 61 72 7b 6c 6f 63 |ls} and |\var{loc|
|00001080| 61 6c 73 7d 20 64 69 63 | 74 69 6f 6e 61 72 69 65 |als} dic|tionarie|
|00001090| 73 20 61 73 20 67 6c 6f | 62 61 6c 20 61 6e 64 20 |s as glo|bal and |
|000010a0| 6c 6f 63 61 6c 20 6e 61 | 6d 65 0d 20 20 73 70 61 |local na|me. spa|
|000010b0| 63 65 2e 20 20 49 66 20 | 74 68 65 20 5c 76 61 72 |ce. If |the \var|
|000010c0| 7b 6c 6f 63 61 6c 73 7d | 20 64 69 63 74 69 6f 6e |{locals}| diction|
|000010d0| 61 72 79 20 69 73 20 6f | 6d 69 74 74 65 64 20 69 |ary is o|mitted i|
|000010e0| 74 20 64 65 66 61 75 6c | 74 73 20 74 6f 0d 20 20 |t defaul|ts to. |
|000010f0| 74 68 65 20 5c 76 61 72 | 7b 67 6c 6f 62 61 6c 73 |the \var|{globals|
|00001100| 7d 20 64 69 63 74 69 6f | 6e 61 72 79 2e 20 20 49 |} dictio|nary. I|
|00001110| 66 20 62 6f 74 68 20 64 | 69 63 74 69 6f 6e 61 72 |f both d|ictionar|
|00001120| 69 65 73 20 61 72 65 20 | 6f 6d 69 74 74 65 64 2c |ies are |omitted,|
|00001130| 20 74 68 65 0d 20 20 65 | 78 70 72 65 73 73 69 6f | the. e|xpressio|
|00001140| 6e 20 69 73 20 65 78 65 | 63 75 74 65 64 20 69 6e |n is exe|cuted in|
|00001150| 20 74 68 65 20 65 6e 76 | 69 72 6f 6e 6d 65 6e 74 | the env|ironment|
|00001160| 20 77 68 65 72 65 20 5c | 63 6f 64 65 7b 65 76 61 | where \|code{eva|
|00001170| 6c 7d 20 69 73 0d 20 20 | 63 61 6c 6c 65 64 2e 20 |l} is. |called. |
|00001180| 20 54 68 65 20 72 65 74 | 75 72 6e 20 76 61 6c 75 | The ret|urn valu|
|00001190| 65 20 69 73 20 74 68 65 | 20 72 65 73 75 6c 74 20 |e is the| result |
|000011a0| 6f 66 20 74 68 65 20 65 | 76 61 6c 75 61 74 65 64 |of the e|valuated|
|000011b0| 20 65 78 70 72 65 73 73 | 69 6f 6e 2e 0d 20 20 53 | express|ion.. S|
|000011c0| 79 6e 74 61 78 20 65 72 | 72 6f 72 73 20 61 72 65 |yntax er|rors are|
|000011d0| 20 72 65 70 6f 72 74 65 | 64 20 61 73 20 65 78 63 | reporte|d as exc|
|000011e0| 65 70 74 69 6f 6e 73 2e | 20 20 45 78 61 6d 70 6c |eptions.| Exampl|
|000011f0| 65 3a 0d 0d 5c 62 63 6f | 64 65 5c 62 65 67 69 6e |e:..\bco|de\begin|
|00001200| 7b 76 65 72 62 61 74 69 | 6d 7d 0d 3e 3e 3e 20 78 |{verbati|m}.>>> x|
|00001210| 20 3d 20 31 0d 3e 3e 3e | 20 70 72 69 6e 74 20 65 | = 1.>>>| print e|
|00001220| 76 61 6c 28 27 78 2b 31 | 27 29 0d 32 0d 3e 3e 3e |val('x+1|').2.>>>|
|00001230| 20 0d 5c 65 6e 64 7b 76 | 65 72 62 61 74 69 6d 7d | .\end{v|erbatim}|
|00001240| 5c 65 63 6f 64 65 0d 0d | 20 20 54 68 69 73 20 66 |\ecode..| This f|
|00001250| 75 6e 63 74 69 6f 6e 20 | 63 61 6e 20 61 6c 73 6f |unction |can also|
|00001260| 20 62 65 20 75 73 65 64 | 20 74 6f 20 65 78 65 63 | be used| to exec|
|00001270| 75 74 65 20 61 72 62 69 | 74 72 61 72 79 20 63 6f |ute arbi|trary co|
|00001280| 64 65 20 6f 62 6a 65 63 | 74 73 0d 20 20 28 65 2e |de objec|ts. (e.|
|00001290| 67 2e 5c 20 63 72 65 61 | 74 65 64 20 62 79 20 5c |g.\ crea|ted by \|
|000012a0| 63 6f 64 65 7b 63 6f 6d | 70 69 6c 65 28 29 7d 29 |code{com|pile()})|
|000012b0| 2e 20 20 49 6e 20 74 68 | 69 73 20 63 61 73 65 20 |. In th|is case |
|000012c0| 70 61 73 73 20 61 20 63 | 6f 64 65 0d 20 20 6f 62 |pass a c|ode. ob|
|000012d0| 6a 65 63 74 20 69 6e 73 | 74 65 61 64 20 6f 66 20 |ject ins|tead of |
|000012e0| 61 20 73 74 72 69 6e 67 | 2e 20 20 54 68 65 20 63 |a string|. The c|
|000012f0| 6f 64 65 20 6f 62 6a 65 | 63 74 20 6d 75 73 74 20 |ode obje|ct must |
|00001300| 68 61 76 65 20 62 65 65 | 6e 20 63 6f 6d 70 69 6c |have bee|n compil|
|00001310| 65 64 0d 20 20 70 61 73 | 73 69 6e 67 20 5c 63 6f |ed. pas|sing \co|
|00001320| 64 65 7b 27 65 76 61 6c | 27 7d 20 74 6f 20 74 68 |de{'eval|'} to th|
|00001330| 65 20 5c 76 61 72 7b 6b | 69 6e 64 7d 20 61 72 67 |e \var{k|ind} arg|
|00001340| 75 6d 65 6e 74 2e 0d 0d | 20 20 48 69 6e 74 73 3a |ument...| Hints:|
|00001350| 20 64 79 6e 61 6d 69 63 | 20 65 78 65 63 75 74 69 | dynamic| executi|
|00001360| 6f 6e 20 6f 66 20 73 74 | 61 74 65 6d 65 6e 74 73 |on of st|atements|
|00001370| 20 69 73 20 73 75 70 70 | 6f 72 74 65 64 20 62 79 | is supp|orted by|
|00001380| 20 74 68 65 0d 20 20 5c | 63 6f 64 65 7b 65 78 65 | the. \|code{exe|
|00001390| 63 7d 20 73 74 61 74 65 | 6d 65 6e 74 2e 20 20 45 |c} state|ment. E|
|000013a0| 78 65 63 75 74 69 6f 6e | 20 6f 66 20 73 74 61 74 |xecution| of stat|
|000013b0| 65 6d 65 6e 74 73 20 66 | 72 6f 6d 20 61 20 66 69 |ements f|rom a fi|
|000013c0| 6c 65 20 69 73 0d 20 20 | 73 75 70 70 6f 72 74 65 |le is. |supporte|
|000013d0| 64 20 62 79 20 74 68 65 | 20 5c 63 6f 64 65 7b 65 |d by the| \code{e|
|000013e0| 78 65 63 66 69 6c 65 28 | 29 7d 20 66 75 6e 63 74 |xecfile(|)} funct|
|000013f0| 69 6f 6e 2e 20 20 54 68 | 65 20 5c 63 6f 64 65 7b |ion. Th|e \code{|
|00001400| 67 6c 6f 62 61 6c 73 28 | 29 7d 0d 20 20 61 6e 64 |globals(|)}. and|
|00001410| 20 5c 63 6f 64 65 7b 6c | 6f 63 61 6c 73 28 29 7d | \code{l|ocals()}|
|00001420| 20 66 75 6e 63 74 69 6f | 6e 73 20 72 65 74 75 72 | functio|ns retur|
|00001430| 6e 73 20 74 68 65 20 63 | 75 72 72 65 6e 74 20 67 |ns the c|urrent g|
|00001440| 6c 6f 62 61 6c 20 61 6e | 64 20 6c 6f 63 61 6c 0d |lobal an|d local.|
|00001450| 20 20 64 69 63 74 69 6f | 6e 61 72 79 2c 20 72 65 | dictio|nary, re|
|00001460| 73 70 65 63 74 69 76 65 | 6c 79 2c 20 77 68 69 63 |spective|ly, whic|
|00001470| 68 20 6d 61 79 20 62 65 | 20 75 73 65 66 75 6c 0d |h may be| useful.|
|00001480| 20 20 74 6f 20 70 61 73 | 73 20 61 72 6f 75 6e 64 | to pas|s around|
|00001490| 20 66 6f 72 20 75 73 65 | 20 62 79 20 5c 63 6f 64 | for use| by \cod|
|000014a0| 65 7b 65 76 61 6c 28 29 | 7d 20 6f 72 20 5c 63 6f |e{eval()|} or \co|
|000014b0| 64 65 7b 65 78 65 63 66 | 69 6c 65 28 29 7d 2e 0d |de{execf|ile()}..|
|000014c0| 0d 5c 65 6e 64 7b 66 75 | 6e 63 64 65 73 63 7d 0d |.\end{fu|ncdesc}.|
|000014d0| 0d 5c 62 65 67 69 6e 7b | 66 75 6e 63 64 65 73 63 |.\begin{|funcdesc|
|000014e0| 7d 7b 65 78 65 63 66 69 | 6c 65 7d 7b 66 69 6c 65 |}{execfi|le}{file|
|000014f0| 5c 6f 70 74 69 6f 6e 61 | 6c 7b 5c 2c 20 67 6c 6f |\optiona|l{\, glo|
|00001500| 62 61 6c 73 5c 6f 70 74 | 69 6f 6e 61 6c 7b 5c 2c |bals\opt|ional{\,|
|00001510| 20 6c 6f 63 61 6c 73 7d | 7d 7d 0d 20 20 54 68 69 | locals}|}}. Thi|
|00001520| 73 20 66 75 6e 63 74 69 | 6f 6e 20 69 73 20 73 69 |s functi|on is si|
|00001530| 6d 69 6c 61 72 20 74 6f | 20 74 68 65 0d 20 20 5c |milar to| the. \|
|00001540| 63 6f 64 65 7b 65 78 65 | 63 7d 20 73 74 61 74 65 |code{exe|c} state|
|00001550| 6d 65 6e 74 2c 20 62 75 | 74 20 70 61 72 73 65 73 |ment, bu|t parses|
|00001560| 20 61 20 66 69 6c 65 20 | 69 6e 73 74 65 61 64 20 | a file |instead |
|00001570| 6f 66 20 61 20 73 74 72 | 69 6e 67 2e 20 20 49 74 |of a str|ing. It|
|00001580| 20 69 73 0d 20 20 64 69 | 66 66 65 72 65 6e 74 20 | is. di|fferent |
|00001590| 66 72 6f 6d 20 74 68 65 | 20 5c 63 6f 64 65 7b 69 |from the| \code{i|
|000015a0| 6d 70 6f 72 74 7d 20 73 | 74 61 74 65 6d 65 6e 74 |mport} s|tatement|
|000015b0| 20 69 6e 20 74 68 61 74 | 20 69 74 20 64 6f 65 73 | in that| it does|
|000015c0| 20 6e 6f 74 20 75 73 65 | 0d 20 20 74 68 65 20 6d | not use|. the m|
|000015d0| 6f 64 75 6c 65 20 61 64 | 6d 69 6e 69 73 74 72 61 |odule ad|ministra|
|000015e0| 74 69 6f 6e 20 2d 2d 2d | 20 69 74 20 72 65 61 64 |tion ---| it read|
|000015f0| 73 20 74 68 65 20 66 69 | 6c 65 20 75 6e 63 6f 6e |s the fi|le uncon|
|00001600| 64 69 74 69 6f 6e 61 6c | 6c 79 20 61 6e 64 0d 20 |ditional|ly and. |
|00001610| 20 64 6f 65 73 20 6e 6f | 74 20 63 72 65 61 74 65 | does no|t create|
|00001620| 20 61 20 6e 65 77 20 6d | 6f 64 75 6c 65 2e 5c 66 | a new m|odule.\f|
|00001630| 6f 6f 74 6e 6f 74 65 7b | 49 74 20 69 73 20 75 73 |ootnote{|It is us|
|00001640| 65 64 20 72 65 6c 61 74 | 69 76 65 6c 79 20 72 61 |ed relat|ively ra|
|00001650| 72 65 6c 79 0d 20 20 73 | 6f 20 64 6f 65 73 20 6e |rely. s|o does n|
|00001660| 6f 74 20 77 61 72 72 61 | 6e 74 20 62 65 69 6e 67 |ot warra|nt being|
|00001670| 20 6d 61 64 65 20 69 6e | 74 6f 20 61 20 73 74 61 | made in|to a sta|
|00001680| 74 65 6d 65 6e 74 2e 7d | 0d 0d 20 20 54 68 65 20 |tement.}|.. The |
|00001690| 61 72 67 75 6d 65 6e 74 | 73 20 61 72 65 20 61 20 |argument|s are a |
|000016a0| 66 69 6c 65 20 6e 61 6d | 65 20 61 6e 64 20 74 77 |file nam|e and tw|
|000016b0| 6f 20 6f 70 74 69 6f 6e | 61 6c 20 64 69 63 74 69 |o option|al dicti|
|000016c0| 6f 6e 61 72 69 65 73 2e | 20 20 54 68 65 0d 20 20 |onaries.| The. |
|000016d0| 66 69 6c 65 20 69 73 20 | 70 61 72 73 65 64 20 61 |file is |parsed a|
|000016e0| 6e 64 20 65 76 61 6c 75 | 61 74 65 64 20 61 73 20 |nd evalu|ated as |
|000016f0| 61 20 73 65 71 75 65 6e | 63 65 20 6f 66 20 50 79 |a sequen|ce of Py|
|00001700| 74 68 6f 6e 20 73 74 61 | 74 65 6d 65 6e 74 73 0d |thon sta|tements.|
|00001710| 20 20 28 73 69 6d 69 6c | 61 72 6c 79 20 74 6f 20 | (simil|arly to |
|00001720| 61 20 6d 6f 64 75 6c 65 | 29 20 75 73 69 6e 67 20 |a module|) using |
|00001730| 74 68 65 20 5c 76 61 72 | 7b 67 6c 6f 62 61 6c 73 |the \var|{globals|
|00001740| 7d 20 61 6e 64 20 5c 76 | 61 72 7b 6c 6f 63 61 6c |} and \v|ar{local|
|00001750| 73 7d 0d 20 20 64 69 63 | 74 69 6f 6e 61 72 69 65 |s}. dic|tionarie|
|00001760| 73 20 61 73 20 67 6c 6f | 62 61 6c 20 61 6e 64 20 |s as glo|bal and |
|00001770| 6c 6f 63 61 6c 20 6e 61 | 6d 65 20 73 70 61 63 65 |local na|me space|
|00001780| 2e 20 20 49 66 20 74 68 | 65 20 5c 76 61 72 7b 6c |. If th|e \var{l|
|00001790| 6f 63 61 6c 73 7d 0d 20 | 20 64 69 63 74 69 6f 6e |ocals}. | diction|
|000017a0| 61 72 79 20 69 73 20 6f | 6d 69 74 74 65 64 20 69 |ary is o|mitted i|
|000017b0| 74 20 64 65 66 61 75 6c | 74 73 20 74 6f 20 74 68 |t defaul|ts to th|
|000017c0| 65 20 5c 76 61 72 7b 67 | 6c 6f 62 61 6c 73 7d 20 |e \var{g|lobals} |
|000017d0| 64 69 63 74 69 6f 6e 61 | 72 79 2e 0d 20 20 49 66 |dictiona|ry.. If|
|000017e0| 20 62 6f 74 68 20 64 69 | 63 74 69 6f 6e 61 72 69 | both di|ctionari|
|000017f0| 65 73 20 61 72 65 20 6f | 6d 69 74 74 65 64 2c 20 |es are o|mitted, |
|00001800| 74 68 65 20 65 78 70 72 | 65 73 73 69 6f 6e 20 69 |the expr|ession i|
|00001810| 73 20 65 78 65 63 75 74 | 65 64 20 69 6e 20 74 68 |s execut|ed in th|
|00001820| 65 0d 20 20 65 6e 76 69 | 72 6f 6e 6d 65 6e 74 20 |e. envi|ronment |
|00001830| 77 68 65 72 65 20 5c 63 | 6f 64 65 7b 65 78 65 63 |where \c|ode{exec|
|00001840| 66 69 6c 65 28 29 7d 20 | 69 73 20 63 61 6c 6c 65 |file()} |is calle|
|00001850| 64 2e 20 20 54 68 65 20 | 72 65 74 75 72 6e 20 76 |d. The |return v|
|00001860| 61 6c 75 65 20 69 73 0d | 20 20 5c 63 6f 64 65 7b |alue is.| \code{|
|00001870| 4e 6f 6e 65 7d 2e 0d 5c | 65 6e 64 7b 66 75 6e 63 |None}..\|end{func|
|00001880| 64 65 73 63 7d 0d 0d 5c | 62 65 67 69 6e 7b 66 75 |desc}..\|begin{fu|
|00001890| 6e 63 64 65 73 63 7d 7b | 66 69 6c 74 65 72 7d 7b |ncdesc}{|filter}{|
|000018a0| 66 75 6e 63 74 69 6f 6e | 5c 2c 20 6c 69 73 74 7d |function|\, list}|
|000018b0| 0d 43 6f 6e 73 74 72 75 | 63 74 20 61 20 6c 69 73 |.Constru|ct a lis|
|000018c0| 74 20 66 72 6f 6d 20 74 | 68 6f 73 65 20 65 6c 65 |t from t|hose ele|
|000018d0| 6d 65 6e 74 73 20 6f 66 | 20 5c 76 61 72 7b 6c 69 |ments of| \var{li|
|000018e0| 73 74 7d 20 66 6f 72 20 | 77 68 69 63 68 0d 5c 76 |st} for |which.\v|
|000018f0| 61 72 7b 66 75 6e 63 74 | 69 6f 6e 7d 20 72 65 74 |ar{funct|ion} ret|
|00001900| 75 72 6e 73 20 74 72 75 | 65 2e 20 20 49 66 20 5c |urns tru|e. If \|
|00001910| 76 61 72 7b 6c 69 73 74 | 7d 20 69 73 20 61 20 73 |var{list|} is a s|
|00001920| 74 72 69 6e 67 20 6f 72 | 20 61 20 74 75 70 6c 65 |tring or| a tuple|
|00001930| 2c 0d 74 68 65 20 72 65 | 73 75 6c 74 20 61 6c 73 |,.the re|sult als|
|00001940| 6f 20 68 61 73 20 74 68 | 61 74 20 74 79 70 65 3b |o has th|at type;|
|00001950| 20 6f 74 68 65 72 77 69 | 73 65 20 69 74 20 69 73 | otherwi|se it is|
|00001960| 20 61 6c 77 61 79 73 20 | 61 20 6c 69 73 74 2e 20 | always |a list. |
|00001970| 20 49 66 0d 5c 76 61 72 | 7b 66 75 6e 63 74 69 6f | If.\var|{functio|
|00001980| 6e 7d 20 69 73 20 5c 63 | 6f 64 65 7b 4e 6f 6e 65 |n} is \c|ode{None|
|00001990| 7d 2c 20 74 68 65 20 69 | 64 65 6e 74 69 74 79 20 |}, the i|dentity |
|000019a0| 66 75 6e 63 74 69 6f 6e | 20 69 73 20 61 73 73 75 |function| is assu|
|000019b0| 6d 65 64 2c 0d 69 2e 65 | 2e 5c 20 61 6c 6c 20 65 |med,.i.e|.\ all e|
|000019c0| 6c 65 6d 65 6e 74 73 20 | 6f 66 20 5c 76 61 72 7b |lements |of \var{|
|000019d0| 6c 69 73 74 7d 20 74 68 | 61 74 20 61 72 65 20 66 |list} th|at are f|
|000019e0| 61 6c 73 65 20 28 7a 65 | 72 6f 20 6f 72 20 65 6d |alse (ze|ro or em|
|000019f0| 70 74 79 29 20 61 72 65 | 0d 72 65 6d 6f 76 65 64 |pty) are|.removed|
|00001a00| 2e 0d 5c 65 6e 64 7b 66 | 75 6e 63 64 65 73 63 7d |..\end{f|uncdesc}|
|00001a10| 0d 0d 5c 62 65 67 69 6e | 7b 66 75 6e 63 64 65 73 |..\begin|{funcdes|
|00001a20| 63 7d 7b 66 6c 6f 61 74 | 7d 7b 78 7d 0d 20 20 43 |c}{float|}{x}. C|
|00001a30| 6f 6e 76 65 72 74 20 61 | 20 6e 75 6d 62 65 72 20 |onvert a| number |
|00001a40| 74 6f 20 66 6c 6f 61 74 | 69 6e 67 20 70 6f 69 6e |to float|ing poin|
|00001a50| 74 2e 20 20 54 68 65 20 | 61 72 67 75 6d 65 6e 74 |t. The |argument|
|00001a60| 20 6d 61 79 20 62 65 20 | 61 20 70 6c 61 69 6e 20 | may be |a plain |
|00001a70| 6f 72 0d 20 20 6c 6f 6e | 67 20 69 6e 74 65 67 65 |or. lon|g intege|
|00001a80| 72 20 6f 72 20 61 20 66 | 6c 6f 61 74 69 6e 67 20 |r or a f|loating |
|00001a90| 70 6f 69 6e 74 20 6e 75 | 6d 62 65 72 2e 0d 5c 65 |point nu|mber..\e|
|00001aa0| 6e 64 7b 66 75 6e 63 64 | 65 73 63 7d 0d 0d 5c 62 |nd{funcd|esc}..\b|
|00001ab0| 65 67 69 6e 7b 66 75 6e | 63 64 65 73 63 7d 7b 67 |egin{fun|cdesc}{g|
|00001ac0| 65 74 61 74 74 72 7d 7b | 6f 62 6a 65 63 74 5c 2c |etattr}{|object\,|
|00001ad0| 20 6e 61 6d 65 7d 0d 20 | 20 54 68 65 20 61 72 67 | name}. | The arg|
|00001ae0| 75 6d 65 6e 74 73 20 61 | 72 65 20 61 6e 20 6f 62 |uments a|re an ob|
|00001af0| 6a 65 63 74 20 61 6e 64 | 20 61 20 73 74 72 69 6e |ject and| a strin|
|00001b00| 67 2e 20 20 54 68 65 20 | 73 74 72 69 6e 67 20 6d |g. The |string m|
|00001b10| 75 73 74 20 62 65 20 74 | 68 65 0d 20 20 6e 61 6d |ust be t|he. nam|
|00001b20| 65 0d 20 20 6f 66 20 6f | 6e 65 20 6f 66 20 74 68 |e. of o|ne of th|
|00001b30| 65 20 6f 62 6a 65 63 74 | 27 73 20 61 74 74 72 69 |e object|'s attri|
|00001b40| 62 75 74 65 73 2e 20 20 | 54 68 65 20 72 65 73 75 |butes. |The resu|
|00001b50| 6c 74 20 69 73 20 74 68 | 65 20 76 61 6c 75 65 20 |lt is th|e value |
|00001b60| 6f 66 20 74 68 61 74 0d | 20 20 61 74 74 72 69 62 |of that.| attrib|
|00001b70| 75 74 65 2e 20 20 46 6f | 72 20 65 78 61 6d 70 6c |ute. Fo|r exampl|
|00001b80| 65 2c 20 5c 63 6f 64 65 | 7b 67 65 74 61 74 74 72 |e, \code|{getattr|
|00001b90| 28 5c 76 61 72 7b 78 7d | 2c 20 27 5c 76 61 72 7b |(\var{x}|, '\var{|
|00001ba0| 66 6f 6f 62 61 72 7d 27 | 29 7d 20 69 73 20 65 71 |foobar}'|)} is eq|
|00001bb0| 75 69 76 61 6c 65 6e 74 | 20 74 6f 0d 20 20 5c 63 |uivalent| to. \c|
|00001bc0| 6f 64 65 7b 5c 76 61 72 | 7b 78 7d 2e 5c 76 61 72 |ode{\var|{x}.\var|
|00001bd0| 7b 66 6f 6f 62 61 72 7d | 7d 2e 0d 5c 65 6e 64 7b |{foobar}|}..\end{|
|00001be0| 66 75 6e 63 64 65 73 63 | 7d 0d 0d 5c 62 65 67 69 |funcdesc|}..\begi|
|00001bf0| 6e 7b 66 75 6e 63 64 65 | 73 63 7d 7b 67 6c 6f 62 |n{funcde|sc}{glob|
|00001c00| 61 6c 73 7d 7b 7d 0d 52 | 65 74 75 72 6e 20 61 20 |als}{}.R|eturn a |
|00001c10| 64 69 63 74 69 6f 6e 61 | 72 79 20 72 65 70 72 65 |dictiona|ry repre|
|00001c20| 73 65 6e 74 69 6e 67 20 | 74 68 65 20 63 75 72 72 |senting |the curr|
|00001c30| 65 6e 74 20 67 6c 6f 62 | 61 6c 20 73 79 6d 62 6f |ent glob|al symbo|
|00001c40| 6c 20 74 61 62 6c 65 2e | 0d 54 68 69 73 20 69 73 |l table.|.This is|
|00001c50| 20 61 6c 77 61 79 73 20 | 74 68 65 20 64 69 63 74 | always |the dict|
|00001c60| 69 6f 6e 61 72 79 20 6f | 66 20 74 68 65 20 63 75 |ionary o|f the cu|
|00001c70| 72 72 65 6e 74 20 6d 6f | 64 75 6c 65 20 28 69 6e |rrent mo|dule (in|
|00001c80| 73 69 64 65 20 61 0d 66 | 75 6e 63 74 69 6f 6e 20 |side a.f|unction |
|00001c90| 6f 72 20 6d 65 74 68 6f | 64 2c 20 74 68 69 73 20 |or metho|d, this |
|00001ca0| 69 73 20 74 68 65 20 6d | 6f 64 75 6c 65 20 77 68 |is the m|odule wh|
|00001cb0| 65 72 65 20 69 74 20 69 | 73 20 64 65 66 69 6e 65 |ere it i|s define|
|00001cc0| 64 2c 20 6e 6f 74 20 74 | 68 65 0d 6d 6f 64 75 6c |d, not t|he.modul|
|00001cd0| 65 20 66 72 6f 6d 20 77 | 68 69 63 68 20 69 74 20 |e from w|hich it |
|00001ce0| 69 73 20 63 61 6c 6c 65 | 64 29 2e 0d 5c 65 6e 64 |is calle|d)..\end|
|00001cf0| 7b 66 75 6e 63 64 65 73 | 63 7d 0d 0d 5c 62 65 67 |{funcdes|c}..\beg|
|00001d00| 69 6e 7b 66 75 6e 63 64 | 65 73 63 7d 7b 68 61 73 |in{funcd|esc}{has|
|00001d10| 61 74 74 72 7d 7b 6f 62 | 6a 65 63 74 5c 2c 20 6e |attr}{ob|ject\, n|
|00001d20| 61 6d 65 7d 0d 20 20 54 | 68 65 20 61 72 67 75 6d |ame}. T|he argum|
|00001d30| 65 6e 74 73 20 61 72 65 | 20 61 6e 20 6f 62 6a 65 |ents are| an obje|
|00001d40| 63 74 20 61 6e 64 20 61 | 20 73 74 72 69 6e 67 2e |ct and a| string.|
|00001d50| 20 20 54 68 65 20 72 65 | 73 75 6c 74 20 69 73 20 | The re|sult is |
|00001d60| 31 20 69 66 20 74 68 65 | 0d 20 20 73 74 72 69 6e |1 if the|. strin|
|00001d70| 67 20 69 73 20 74 68 65 | 20 6e 61 6d 65 20 6f 66 |g is the| name of|
|00001d80| 20 6f 6e 65 20 6f 66 20 | 74 68 65 20 6f 62 6a 65 | one of |the obje|
|00001d90| 63 74 27 73 20 61 74 74 | 72 69 62 75 74 65 73 2c |ct's att|ributes,|
|00001da0| 20 30 20 69 66 20 6e 6f | 74 2e 0d 20 20 28 54 68 | 0 if no|t.. (Th|
|00001db0| 69 73 20 69 73 20 69 6d | 70 6c 65 6d 65 6e 74 65 |is is im|plemente|
|00001dc0| 64 20 62 79 20 63 61 6c | 6c 69 6e 67 20 5c 63 6f |d by cal|ling \co|
|00001dd0| 64 65 7b 67 65 74 61 74 | 74 72 28 6f 62 6a 65 63 |de{getat|tr(objec|
|00001de0| 74 2c 20 6e 61 6d 65 29 | 7d 20 61 6e 64 0d 20 20 |t, name)|} and. |
|00001df0| 73 65 65 69 6e 67 20 77 | 68 65 74 68 65 72 20 69 |seeing w|hether i|
|00001e00| 74 20 72 61 69 73 65 73 | 20 61 6e 20 65 78 63 65 |t raises| an exce|
|00001e10| 70 74 69 6f 6e 20 6f 72 | 20 6e 6f 74 2e 29 0d 5c |ption or| not.).\|
|00001e20| 65 6e 64 7b 66 75 6e 63 | 64 65 73 63 7d 0d 0d 5c |end{func|desc}..\|
|00001e30| 62 65 67 69 6e 7b 66 75 | 6e 63 64 65 73 63 7d 7b |begin{fu|ncdesc}{|
|00001e40| 68 61 73 68 7d 7b 6f 62 | 6a 65 63 74 7d 0d 20 20 |hash}{ob|ject}. |
|00001e50| 52 65 74 75 72 6e 20 74 | 68 65 20 68 61 73 68 20 |Return t|he hash |
|00001e60| 76 61 6c 75 65 20 6f 66 | 20 74 68 65 20 6f 62 6a |value of| the obj|
|00001e70| 65 63 74 20 28 69 66 20 | 69 74 20 68 61 73 20 6f |ect (if |it has o|
|00001e80| 6e 65 29 2e 20 20 48 61 | 73 68 20 76 61 6c 75 65 |ne). Ha|sh value|
|00001e90| 73 0d 20 20 61 72 65 20 | 33 32 2d 62 69 74 20 69 |s. are |32-bit i|
|00001ea0| 6e 74 65 67 65 72 73 2e | 20 20 54 68 65 79 20 61 |ntegers.| They a|
|00001eb0| 72 65 20 75 73 65 64 20 | 74 6f 20 71 75 69 63 6b |re used |to quick|
|00001ec0| 6c 79 20 63 6f 6d 70 61 | 72 65 20 64 69 63 74 69 |ly compa|re dicti|
|00001ed0| 6f 6e 61 72 79 0d 20 20 | 6b 65 79 73 20 64 75 72 |onary. |keys dur|
|00001ee0| 69 6e 67 20 61 20 64 69 | 63 74 69 6f 6e 61 72 79 |ing a di|ctionary|
|00001ef0| 20 6c 6f 6f 6b 75 70 2e | 20 20 4e 75 6d 65 72 69 | lookup.| Numeri|
|00001f00| 63 20 76 61 6c 75 65 73 | 20 74 68 61 74 20 63 6f |c values| that co|
|00001f10| 6d 70 61 72 65 20 65 71 | 75 61 6c 0d 20 20 68 61 |mpare eq|ual. ha|
|00001f20| 76 65 20 74 68 65 20 73 | 61 6d 65 20 68 61 73 68 |ve the s|ame hash|
|00001f30| 20 76 61 6c 75 65 20 28 | 65 76 65 6e 20 69 66 20 | value (|even if |
|00001f40| 74 68 65 79 20 61 72 65 | 20 6f 66 20 64 69 66 66 |they are| of diff|
|00001f50| 65 72 65 6e 74 20 74 79 | 70 65 73 2c 20 65 2e 67 |erent ty|pes, e.g|
|00001f60| 2e 0d 20 20 31 20 61 6e | 64 20 31 2e 30 29 2e 0d |.. 1 an|d 1.0)..|
|00001f70| 5c 65 6e 64 7b 66 75 6e | 63 64 65 73 63 7d 0d 0d |\end{fun|cdesc}..|
|00001f80| 5c 62 65 67 69 6e 7b 66 | 75 6e 63 64 65 73 63 7d |\begin{f|uncdesc}|
|00001f90| 7b 68 65 78 7d 7b 78 7d | 0d 20 20 43 6f 6e 76 65 |{hex}{x}|. Conve|
|00001fa0| 72 74 20 61 6e 20 69 6e | 74 65 67 65 72 20 6e 75 |rt an in|teger nu|
|00001fb0| 6d 62 65 72 20 28 6f 66 | 20 61 6e 79 20 73 69 7a |mber (of| any siz|
|00001fc0| 65 29 20 74 6f 20 61 20 | 68 65 78 61 64 65 63 69 |e) to a |hexadeci|
|00001fd0| 6d 61 6c 20 73 74 72 69 | 6e 67 2e 0d 20 20 54 68 |mal stri|ng.. Th|
|00001fe0| 65 20 72 65 73 75 6c 74 | 20 69 73 20 61 20 76 61 |e result| is a va|
|00001ff0| 6c 69 64 20 50 79 74 68 | 6f 6e 20 65 78 70 72 65 |lid Pyth|on expre|
|00002000| 73 73 69 6f 6e 2e 0d 5c | 65 6e 64 7b 66 75 6e 63 |ssion..\|end{func|
|00002010| 64 65 73 63 7d 0d 0d 5c | 62 65 67 69 6e 7b 66 75 |desc}..\|begin{fu|
|00002020| 6e 63 64 65 73 63 7d 7b | 69 64 7d 7b 6f 62 6a 65 |ncdesc}{|id}{obje|
|00002030| 63 74 7d 0d 20 20 52 65 | 74 75 72 6e 20 74 68 65 |ct}. Re|turn the|
|00002040| 20 60 69 64 65 6e 74 69 | 74 79 27 20 6f 66 20 61 | `identi|ty' of a|
|00002050| 6e 20 6f 62 6a 65 63 74 | 2e 20 20 54 68 69 73 20 |n object|. This |
|00002060| 69 73 20 61 6e 20 69 6e | 74 65 67 65 72 20 77 68 |is an in|teger wh|
|00002070| 69 63 68 20 69 73 0d 20 | 20 67 75 61 72 61 6e 74 |ich is. | guarant|
|00002080| 65 65 64 20 74 6f 20 62 | 65 20 75 6e 69 71 75 65 |eed to b|e unique|
|00002090| 20 61 6e 64 20 63 6f 6e | 73 74 61 6e 74 20 66 6f | and con|stant fo|
|000020a0| 72 20 74 68 69 73 20 6f | 62 6a 65 63 74 20 64 75 |r this o|bject du|
|000020b0| 72 69 6e 67 20 69 74 73 | 0d 20 20 6c 69 66 65 74 |ring its|. lifet|
|000020c0| 69 6d 65 2e 20 20 28 54 | 77 6f 20 6f 62 6a 65 63 |ime. (T|wo objec|
|000020d0| 74 73 20 77 68 6f 73 65 | 20 6c 69 66 65 74 69 6d |ts whose| lifetim|
|000020e0| 65 73 20 61 72 65 20 64 | 69 73 6a 75 6e 63 74 20 |es are d|isjunct |
|000020f0| 6d 61 79 20 68 61 76 65 | 20 74 68 65 0d 20 20 73 |may have| the. s|
|00002100| 61 6d 65 20 69 64 28 29 | 20 76 61 6c 75 65 2e 29 |ame id()| value.)|
|00002110| 20 20 28 49 6d 70 6c 65 | 6d 65 6e 74 61 74 69 6f | (Imple|mentatio|
|00002120| 6e 20 6e 6f 74 65 3a 20 | 74 68 69 73 20 69 73 20 |n note: |this is |
|00002130| 74 68 65 20 61 64 64 72 | 65 73 73 20 6f 66 20 74 |the addr|ess of t|
|00002140| 68 65 0d 20 20 6f 62 6a | 65 63 74 2e 29 0d 5c 65 |he. obj|ect.).\e|
|00002150| 6e 64 7b 66 75 6e 63 64 | 65 73 63 7d 0d 0d 5c 62 |nd{funcd|esc}..\b|
|00002160| 65 67 69 6e 7b 66 75 6e | 63 64 65 73 63 7d 7b 69 |egin{fun|cdesc}{i|
|00002170| 6e 70 75 74 7d 7b 5c 6f | 70 74 69 6f 6e 61 6c 7b |nput}{\o|ptional{|
|00002180| 70 72 6f 6d 70 74 7d 7d | 0d 20 20 41 6c 6d 6f 73 |prompt}}|. Almos|
|00002190| 74 20 65 71 75 69 76 61 | 6c 65 6e 74 20 74 6f 20 |t equiva|lent to |
|000021a0| 5c 63 6f 64 65 7b 65 76 | 61 6c 28 72 61 77 5f 69 |\code{ev|al(raw_i|
|000021b0| 6e 70 75 74 28 5c 76 61 | 72 7b 70 72 6f 6d 70 74 |nput(\va|r{prompt|
|000021c0| 7d 29 29 7d 2e 20 20 4c | 69 6b 65 0d 20 20 5c 63 |}))}. L|ike. \c|
|000021d0| 6f 64 65 7b 72 61 77 5f | 69 6e 70 75 74 28 29 7d |ode{raw_|input()}|
|000021e0| 2c 20 74 68 65 20 5c 76 | 61 72 7b 70 72 6f 6d 70 |, the \v|ar{promp|
|000021f0| 74 7d 20 61 72 67 75 6d | 65 6e 74 20 69 73 20 6f |t} argum|ent is o|
|00002200| 70 74 69 6f 6e 61 6c 2e | 20 20 54 68 65 20 64 69 |ptional.| The di|
|00002210| 66 66 65 72 65 6e 63 65 | 0d 20 20 69 73 20 74 68 |fference|. is th|
|00002220| 61 74 20 61 20 6c 6f 6e | 67 20 69 6e 70 75 74 20 |at a lon|g input |
|00002230| 65 78 70 72 65 73 73 69 | 6f 6e 20 6d 61 79 20 62 |expressi|on may b|
|00002240| 65 20 62 72 6f 6b 65 6e | 20 6f 76 65 72 20 6d 75 |e broken| over mu|
|00002250| 6c 74 69 70 6c 65 20 6c | 69 6e 65 73 20 75 73 69 |ltiple l|ines usi|
|00002260| 6e 67 0d 20 20 74 68 65 | 20 62 61 63 6b 73 6c 61 |ng. the| backsla|
|00002270| 73 68 20 63 6f 6e 76 65 | 6e 74 69 6f 6e 2e 0d 5c |sh conve|ntion..\|
|00002280| 65 6e 64 7b 66 75 6e 63 | 64 65 73 63 7d 0d 0d 5c |end{func|desc}..\|
|00002290| 62 65 67 69 6e 7b 66 75 | 6e 63 64 65 73 63 7d 7b |begin{fu|ncdesc}{|
|000022a0| 69 6e 74 7d 7b 78 7d 0d | 20 20 43 6f 6e 76 65 72 |int}{x}.| Conver|
|000022b0| 74 20 61 20 6e 75 6d 62 | 65 72 20 74 6f 20 61 20 |t a numb|er to a |
|000022c0| 70 6c 61 69 6e 20 69 6e | 74 65 67 65 72 2e 20 20 |plain in|teger. |
|000022d0| 54 68 65 20 61 72 67 75 | 6d 65 6e 74 20 6d 61 79 |The argu|ment may|
|000022e0| 20 62 65 20 61 20 70 6c | 61 69 6e 20 6f 72 0d 20 | be a pl|ain or. |
|000022f0| 20 6c 6f 6e 67 20 69 6e | 74 65 67 65 72 20 6f 72 | long in|teger or|
|00002300| 20 61 20 66 6c 6f 61 74 | 69 6e 67 20 70 6f 69 6e | a float|ing poin|
|00002310| 74 20 6e 75 6d 62 65 72 | 2e 20 20 43 6f 6e 76 65 |t number|. Conve|
|00002320| 72 73 69 6f 6e 20 6f 66 | 20 66 6c 6f 61 74 69 6e |rsion of| floatin|
|00002330| 67 0d 20 20 70 6f 69 6e | 74 20 6e 75 6d 62 65 72 |g. poin|t number|
|00002340| 73 20 74 6f 20 69 6e 74 | 65 67 65 72 73 20 69 73 |s to int|egers is|
|00002350| 20 64 65 66 69 6e 65 64 | 20 62 79 20 74 68 65 20 | defined| by the |
|00002360| 43 20 73 65 6d 61 6e 74 | 69 63 73 3b 20 6e 6f 72 |C semant|ics; nor|
|00002370| 6d 61 6c 6c 79 0d 20 20 | 74 68 65 20 63 6f 6e 76 |mally. |the conv|
|00002380| 65 72 73 69 6f 6e 20 74 | 72 75 6e 63 61 74 65 73 |ersion t|runcates|
|00002390| 20 74 6f 77 61 72 64 73 | 20 7a 65 72 6f 2e 5c 66 | towards| zero.\f|
|000023a0| 6f 6f 74 6e 6f 74 65 7b | 54 68 69 73 20 69 73 20 |ootnote{|This is |
|000023b0| 75 67 6c 79 20 2d 2d 2d | 20 74 68 65 0d 20 20 6c |ugly ---| the. l|
|000023c0| 61 6e 67 75 61 67 65 20 | 64 65 66 69 6e 69 74 69 |anguage |definiti|
|000023d0| 6f 6e 20 73 68 6f 75 6c | 64 20 72 65 71 75 69 72 |on shoul|d requir|
|000023e0| 65 20 74 72 75 6e 63 61 | 74 69 6f 6e 20 74 6f 77 |e trunca|tion tow|
|000023f0| 61 72 64 73 20 7a 65 72 | 6f 2e 7d 0d 5c 65 6e 64 |ards zer|o.}.\end|
|00002400| 7b 66 75 6e 63 64 65 73 | 63 7d 0d 0d 5c 62 65 67 |{funcdes|c}..\beg|
|00002410| 69 6e 7b 66 75 6e 63 64 | 65 73 63 7d 7b 6c 65 6e |in{funcd|esc}{len|
|00002420| 7d 7b 73 7d 0d 20 20 52 | 65 74 75 72 6e 20 74 68 |}{s}. R|eturn th|
|00002430| 65 20 6c 65 6e 67 74 68 | 20 28 74 68 65 20 6e 75 |e length| (the nu|
|00002440| 6d 62 65 72 20 6f 66 20 | 69 74 65 6d 73 29 20 6f |mber of |items) o|
|00002450| 66 20 61 6e 20 6f 62 6a | 65 63 74 2e 20 20 54 68 |f an obj|ect. Th|
|00002460| 65 20 61 72 67 75 6d 65 | 6e 74 0d 20 20 6d 61 79 |e argume|nt. may|
|00002470| 20 62 65 20 61 20 73 65 | 71 75 65 6e 63 65 20 28 | be a se|quence (|
|00002480| 73 74 72 69 6e 67 2c 20 | 74 75 70 6c 65 20 6f 72 |string, |tuple or|
|00002490| 20 6c 69 73 74 29 20 6f | 72 20 61 20 6d 61 70 70 | list) o|r a mapp|
|000024a0| 69 6e 67 20 28 64 69 63 | 74 69 6f 6e 61 72 79 29 |ing (dic|tionary)|
|000024b0| 2e 0d 5c 65 6e 64 7b 66 | 75 6e 63 64 65 73 63 7d |..\end{f|uncdesc}|
|000024c0| 0d 0d 5c 62 65 67 69 6e | 7b 66 75 6e 63 64 65 73 |..\begin|{funcdes|
|000024d0| 63 7d 7b 6c 6f 63 61 6c | 73 7d 7b 7d 0d 52 65 74 |c}{local|s}{}.Ret|
|000024e0| 75 72 6e 20 61 20 64 69 | 63 74 69 6f 6e 61 72 79 |urn a di|ctionary|
|000024f0| 20 72 65 70 72 65 73 65 | 6e 74 69 6e 67 20 74 68 | represe|nting th|
|00002500| 65 20 63 75 72 72 65 6e | 74 20 6c 6f 63 61 6c 20 |e curren|t local |
|00002510| 73 79 6d 62 6f 6c 20 74 | 61 62 6c 65 2e 0d 49 6e |symbol t|able..In|
|00002520| 73 69 64 65 20 61 20 66 | 75 6e 63 74 69 6f 6e 2c |side a f|unction,|
|00002530| 20 6d 6f 64 69 66 79 69 | 6e 67 20 74 68 69 73 20 | modifyi|ng this |
|00002540| 64 69 63 74 69 6f 6e 61 | 72 79 20 64 6f 65 73 20 |dictiona|ry does |
|00002550| 6e 6f 74 20 61 6c 77 61 | 79 73 20 68 61 76 65 20 |not alwa|ys have |
|00002560| 74 68 65 0d 64 65 73 69 | 72 65 64 20 65 66 66 65 |the.desi|red effe|
|00002570| 63 74 2e 0d 5c 65 6e 64 | 7b 66 75 6e 63 64 65 73 |ct..\end|{funcdes|
|00002580| 63 7d 0d 0d 5c 62 65 67 | 69 6e 7b 66 75 6e 63 64 |c}..\beg|in{funcd|
|00002590| 65 73 63 7d 7b 6c 6f 6e | 67 7d 7b 78 7d 0d 20 20 |esc}{lon|g}{x}. |
|000025a0| 43 6f 6e 76 65 72 74 20 | 61 20 6e 75 6d 62 65 72 |Convert |a number|
|000025b0| 20 74 6f 20 61 20 6c 6f | 6e 67 20 69 6e 74 65 67 | to a lo|ng integ|
|000025c0| 65 72 2e 20 20 54 68 65 | 20 61 72 67 75 6d 65 6e |er. The| argumen|
|000025d0| 74 20 6d 61 79 20 62 65 | 20 61 20 70 6c 61 69 6e |t may be| a plain|
|000025e0| 20 6f 72 0d 20 20 6c 6f | 6e 67 20 69 6e 74 65 67 | or. lo|ng integ|
|000025f0| 65 72 20 6f 72 20 61 20 | 66 6c 6f 61 74 69 6e 67 |er or a |floating|
|00002600| 20 70 6f 69 6e 74 20 6e | 75 6d 62 65 72 2e 0d 5c | point n|umber..\|
|00002610| 65 6e 64 7b 66 75 6e 63 | 64 65 73 63 7d 0d 0d 5c |end{func|desc}..\|
|00002620| 62 65 67 69 6e 7b 66 75 | 6e 63 64 65 73 63 7d 7b |begin{fu|ncdesc}{|
|00002630| 6d 61 70 7d 7b 66 75 6e | 63 74 69 6f 6e 5c 2c 20 |map}{fun|ction\, |
|00002640| 6c 69 73 74 5c 2c 20 2e | 2e 2e 7d 0d 41 70 70 6c |list\, .|..}.Appl|
|00002650| 79 20 5c 76 61 72 7b 66 | 75 6e 63 74 69 6f 6e 7d |y \var{f|unction}|
|00002660| 20 74 6f 20 65 76 65 72 | 79 20 69 74 65 6d 20 6f | to ever|y item o|
|00002670| 66 20 5c 76 61 72 7b 6c | 69 73 74 7d 20 61 6e 64 |f \var{l|ist} and|
|00002680| 20 72 65 74 75 72 6e 20 | 61 20 6c 69 73 74 0d 6f | return |a list.o|
|00002690| 66 20 74 68 65 20 72 65 | 73 75 6c 74 73 2e 20 20 |f the re|sults. |
|000026a0| 49 66 20 61 64 64 69 74 | 69 6f 6e 61 6c 20 5c 76 |If addit|ional \v|
|000026b0| 61 72 7b 6c 69 73 74 7d | 20 61 72 67 75 6d 65 6e |ar{list}| argumen|
|000026c0| 74 73 20 61 72 65 20 70 | 61 73 73 65 64 2c 20 0d |ts are p|assed, .|
|000026d0| 5c 76 61 72 7b 66 75 6e | 63 74 69 6f 6e 7d 20 6d |\var{fun|ction} m|
|000026e0| 75 73 74 20 74 61 6b 65 | 20 74 68 61 74 20 6d 61 |ust take| that ma|
|000026f0| 6e 79 20 61 72 67 75 6d | 65 6e 74 73 20 61 6e 64 |ny argum|ents and|
|00002700| 20 69 73 20 61 70 70 6c | 69 65 64 20 74 6f 0d 74 | is appl|ied to.t|
|00002710| 68 65 20 69 74 65 6d 73 | 20 6f 66 20 61 6c 6c 20 |he items| of all |
|00002720| 6c 69 73 74 73 20 69 6e | 20 70 61 72 61 6c 6c 65 |lists in| paralle|
|00002730| 6c 3b 20 69 66 20 61 20 | 6c 69 73 74 20 69 73 20 |l; if a |list is |
|00002740| 73 68 6f 72 74 65 72 20 | 74 68 61 6e 20 61 6e 6f |shorter |than ano|
|00002750| 74 68 65 72 0d 69 74 20 | 69 73 20 61 73 73 75 6d |ther.it |is assum|
|00002760| 65 64 20 74 6f 20 62 65 | 20 65 78 74 65 6e 64 65 |ed to be| extende|
|00002770| 64 20 77 69 74 68 20 5c | 63 6f 64 65 7b 4e 6f 6e |d with \|code{Non|
|00002780| 65 7d 20 69 74 65 6d 73 | 2e 20 20 49 66 0d 5c 76 |e} items|. If.\v|
|00002790| 61 72 7b 66 75 6e 63 74 | 69 6f 6e 7d 20 69 73 20 |ar{funct|ion} is |
|000027a0| 5c 63 6f 64 65 7b 4e 6f | 6e 65 7d 2c 20 74 68 65 |\code{No|ne}, the|
|000027b0| 20 69 64 65 6e 74 69 74 | 79 20 66 75 6e 63 74 69 | identit|y functi|
|000027c0| 6f 6e 20 69 73 20 61 73 | 73 75 6d 65 64 3b 20 69 |on is as|sumed; i|
|000027d0| 66 0d 74 68 65 72 65 20 | 61 72 65 20 6d 75 6c 74 |f.there |are mult|
|000027e0| 69 70 6c 65 20 6c 69 73 | 74 20 61 72 67 75 6d 65 |iple lis|t argume|
|000027f0| 6e 74 73 2c 20 5c 63 6f | 64 65 7b 6d 61 70 7d 20 |nts, \co|de{map} |
|00002800| 72 65 74 75 72 6e 73 20 | 61 20 6c 69 73 74 0d 63 |returns |a list.c|
|00002810| 6f 6e 73 69 73 74 69 6e | 67 20 6f 66 20 74 75 70 |onsistin|g of tup|
|00002820| 6c 65 73 20 63 6f 6e 74 | 61 69 6e 69 6e 67 20 74 |les cont|aining t|
|00002830| 68 65 20 63 6f 72 72 65 | 73 70 6f 6e 64 69 6e 67 |he corre|sponding|
|00002840| 20 69 74 65 6d 73 20 66 | 72 6f 6d 20 61 6c 6c 20 | items f|rom all |
|00002850| 6c 69 73 74 73 0d 28 69 | 2e 65 2e 20 61 20 6b 69 |lists.(i|.e. a ki|
|00002860| 6e 64 20 6f 66 20 74 72 | 61 6e 73 70 6f 73 65 20 |nd of tr|anspose |
|00002870| 6f 70 65 72 61 74 69 6f | 6e 29 2e 20 20 54 68 65 |operatio|n). The|
|00002880| 20 5c 76 61 72 7b 6c 69 | 73 74 7d 20 61 72 67 75 | \var{li|st} argu|
|00002890| 6d 65 6e 74 73 20 6d 61 | 79 20 62 65 0d 61 6e 79 |ments ma|y be.any|
|000028a0| 20 6b 69 6e 64 20 6f 66 | 20 73 65 71 75 65 6e 63 | kind of| sequenc|
|000028b0| 65 3b 20 74 68 65 20 72 | 65 73 75 6c 74 20 69 73 |e; the r|esult is|
|000028c0| 20 61 6c 77 61 79 73 20 | 61 20 6c 69 73 74 2e 0d | always |a list..|
|000028d0| 5c 65 6e 64 7b 66 75 6e | 63 64 65 73 63 7d 0d 0d |\end{fun|cdesc}..|
|000028e0| 5c 62 65 67 69 6e 7b 66 | 75 6e 63 64 65 73 63 7d |\begin{f|uncdesc}|
|000028f0| 7b 6d 61 78 7d 7b 73 7d | 0d 20 20 52 65 74 75 72 |{max}{s}|. Retur|
|00002900| 6e 20 74 68 65 20 6c 61 | 72 67 65 73 74 20 69 74 |n the la|rgest it|
|00002910| 65 6d 20 6f 66 20 61 20 | 6e 6f 6e 2d 65 6d 70 74 |em of a |non-empt|
|00002920| 79 20 73 65 71 75 65 6e | 63 65 20 28 73 74 72 69 |y sequen|ce (stri|
|00002930| 6e 67 2c 20 74 75 70 6c | 65 20 6f 72 0d 20 20 6c |ng, tupl|e or. l|
|00002940| 69 73 74 29 2e 0d 5c 65 | 6e 64 7b 66 75 6e 63 64 |ist)..\e|nd{funcd|
|00002950| 65 73 63 7d 0d 0d 5c 62 | 65 67 69 6e 7b 66 75 6e |esc}..\b|egin{fun|
|00002960| 63 64 65 73 63 7d 7b 6d | 69 6e 7d 7b 73 7d 0d 20 |cdesc}{m|in}{s}. |
|00002970| 20 52 65 74 75 72 6e 20 | 74 68 65 20 73 6d 61 6c | Return |the smal|
|00002980| 6c 65 73 74 20 69 74 65 | 6d 20 6f 66 20 61 20 6e |lest ite|m of a n|
|00002990| 6f 6e 2d 65 6d 70 74 79 | 20 73 65 71 75 65 6e 63 |on-empty| sequenc|
|000029a0| 65 20 28 73 74 72 69 6e | 67 2c 20 74 75 70 6c 65 |e (strin|g, tuple|
|000029b0| 20 6f 72 0d 20 20 6c 69 | 73 74 29 2e 0d 5c 65 6e | or. li|st)..\en|
|000029c0| 64 7b 66 75 6e 63 64 65 | 73 63 7d 0d 0d 5c 62 65 |d{funcde|sc}..\be|
|000029d0| 67 69 6e 7b 66 75 6e 63 | 64 65 73 63 7d 7b 6f 63 |gin{func|desc}{oc|
|000029e0| 74 7d 7b 78 7d 0d 20 20 | 43 6f 6e 76 65 72 74 20 |t}{x}. |Convert |
|000029f0| 61 6e 20 69 6e 74 65 67 | 65 72 20 6e 75 6d 62 65 |an integ|er numbe|
|00002a00| 72 20 28 6f 66 20 61 6e | 79 20 73 69 7a 65 29 20 |r (of an|y size) |
|00002a10| 74 6f 20 61 6e 20 6f 63 | 74 61 6c 20 73 74 72 69 |to an oc|tal stri|
|00002a20| 6e 67 2e 20 20 54 68 65 | 0d 20 20 72 65 73 75 6c |ng. The|. resul|
|00002a30| 74 20 69 73 20 61 20 76 | 61 6c 69 64 20 50 79 74 |t is a v|alid Pyt|
|00002a40| 68 6f 6e 20 65 78 70 72 | 65 73 73 69 6f 6e 2e 0d |hon expr|ession..|
|00002a50| 5c 65 6e 64 7b 66 75 6e | 63 64 65 73 63 7d 0d 0d |\end{fun|cdesc}..|
|00002a60| 5c 62 65 67 69 6e 7b 66 | 75 6e 63 64 65 73 63 7d |\begin{f|uncdesc}|
|00002a70| 7b 6f 70 65 6e 7d 7b 66 | 69 6c 65 6e 61 6d 65 5c |{open}{f|ilename\|
|00002a80| 6f 70 74 69 6f 6e 61 6c | 7b 5c 2c 20 6d 6f 64 65 |optional|{\, mode|
|00002a90| 5c 6f 70 74 69 6f 6e 61 | 6c 7b 5c 2c 20 62 75 66 |\optiona|l{\, buf|
|00002aa0| 73 69 7a 65 7d 7d 7d 0d | 20 20 52 65 74 75 72 6e |size}}}.| Return|
|00002ab0| 20 61 20 6e 65 77 20 66 | 69 6c 65 20 6f 62 6a 65 | a new f|ile obje|
|00002ac0| 63 74 20 28 64 65 73 63 | 72 69 62 65 64 20 65 61 |ct (desc|ribed ea|
|00002ad0| 72 6c 69 65 72 20 75 6e | 64 65 72 20 42 75 69 6c |rlier un|der Buil|
|00002ae0| 74 2d 69 6e 20 54 79 70 | 65 73 29 2e 0d 20 20 54 |t-in Typ|es).. T|
|00002af0| 68 65 20 66 69 72 73 74 | 20 74 77 6f 20 61 72 67 |he first| two arg|
|00002b00| 75 6d 65 6e 74 73 20 61 | 72 65 20 74 68 65 20 73 |uments a|re the s|
|00002b10| 61 6d 65 20 61 73 20 66 | 6f 72 20 5c 63 6f 64 65 |ame as f|or \code|
|00002b20| 7b 73 74 64 69 6f 7d 27 | 73 0d 20 20 5c 63 6f 64 |{stdio}'|s. \cod|
|00002b30| 65 7b 66 6f 70 65 6e 28 | 29 7d 3a 20 5c 76 61 72 |e{fopen(|)}: \var|
|00002b40| 7b 66 69 6c 65 6e 61 6d | 65 7d 20 69 73 20 74 68 |{filenam|e} is th|
|00002b50| 65 20 66 69 6c 65 20 6e | 61 6d 65 20 74 6f 20 62 |e file n|ame to b|
|00002b60| 65 20 6f 70 65 6e 65 64 | 2c 0d 20 20 5c 76 61 72 |e opened|,. \var|
|00002b70| 7b 6d 6f 64 65 7d 20 69 | 6e 64 69 63 61 74 65 73 |{mode} i|ndicates|
|00002b80| 20 68 6f 77 20 74 68 65 | 20 66 69 6c 65 20 69 73 | how the| file is|
|00002b90| 20 74 6f 20 62 65 20 6f | 70 65 6e 65 64 3a 20 5c | to be o|pened: \|
|00002ba0| 63 6f 64 65 7b 27 72 27 | 7d 20 66 6f 72 0d 20 20 |code{'r'|} for. |
|00002bb0| 72 65 61 64 69 6e 67 2c | 20 5c 63 6f 64 65 7b 27 |reading,| \code{'|
|00002bc0| 77 27 7d 20 66 6f 72 20 | 77 72 69 74 69 6e 67 20 |w'} for |writing |
|00002bd0| 28 74 72 75 6e 63 61 74 | 69 6e 67 20 61 6e 20 65 |(truncat|ing an e|
|00002be0| 78 69 73 74 69 6e 67 20 | 66 69 6c 65 29 2c 20 61 |xisting |file), a|
|00002bf0| 6e 64 0d 20 20 5c 63 6f | 64 65 7b 27 61 27 7d 20 |nd. \co|de{'a'} |
|00002c00| 6f 70 65 6e 73 20 69 74 | 20 66 6f 72 20 61 70 70 |opens it| for app|
|00002c10| 65 6e 64 69 6e 67 2e 20 | 20 4d 6f 64 65 73 20 5c |ending. | Modes \|
|00002c20| 63 6f 64 65 7b 27 72 2b | 27 7d 2c 20 5c 63 6f 64 |code{'r+|'}, \cod|
|00002c30| 65 7b 27 77 2b 27 7d 20 | 61 6e 64 0d 20 20 5c 63 |e{'w+'} |and. \c|
|00002c40| 6f 64 65 7b 27 61 2b 27 | 7d 20 6f 70 65 6e 20 74 |ode{'a+'|} open t|
|00002c50| 68 65 20 66 69 6c 65 20 | 66 6f 72 20 75 70 64 61 |he file |for upda|
|00002c60| 74 69 6e 67 2c 20 70 72 | 6f 76 69 64 65 64 20 74 |ting, pr|ovided t|
|00002c70| 68 65 20 75 6e 64 65 72 | 6c 79 69 6e 67 0d 20 20 |he under|lying. |
|00002c80| 5c 63 6f 64 65 7b 73 74 | 64 69 6f 7d 20 6c 69 62 |\code{st|dio} lib|
|00002c90| 72 61 72 79 20 75 6e 64 | 65 72 73 74 61 6e 64 73 |rary und|erstands|
|00002ca0| 20 74 68 69 73 2e 20 20 | 4f 6e 20 73 79 73 74 65 | this. |On syste|
|00002cb0| 6d 73 20 74 68 61 74 20 | 64 69 66 66 65 72 65 6e |ms that |differen|
|00002cc0| 74 69 61 74 65 0d 20 20 | 62 65 74 77 65 65 6e 20 |tiate. |between |
|00002cd0| 62 69 6e 61 72 79 20 61 | 6e 64 20 74 65 78 74 20 |binary a|nd text |
|00002ce0| 66 69 6c 65 73 2c 20 5c | 63 6f 64 65 7b 27 62 27 |files, \|code{'b'|
|00002cf0| 7d 20 61 70 70 65 6e 64 | 65 64 20 74 6f 20 74 68 |} append|ed to th|
|00002d00| 65 20 6d 6f 64 65 20 6f | 70 65 6e 73 0d 20 20 74 |e mode o|pens. t|
|00002d10| 68 65 20 66 69 6c 65 20 | 69 6e 20 62 69 6e 61 72 |he file |in binar|
|00002d20| 79 20 6d 6f 64 65 2e 20 | 20 49 66 20 74 68 65 20 |y mode. | If the |
|00002d30| 66 69 6c 65 20 63 61 6e | 6e 6f 74 20 62 65 20 6f |file can|not be o|
|00002d40| 70 65 6e 65 64 2c 20 5c | 63 6f 64 65 7b 49 4f 45 |pened, \|code{IOE|
|00002d50| 72 72 6f 72 7d 0d 20 20 | 69 73 20 72 61 69 73 65 |rror}. |is raise|
|00002d60| 64 2e 0d 49 66 20 5c 76 | 61 72 7b 6d 6f 64 65 7d |d..If \v|ar{mode}|
|00002d70| 20 69 73 20 6f 6d 69 74 | 74 65 64 2c 20 69 74 20 | is omit|ted, it |
|00002d80| 64 65 66 61 75 6c 74 73 | 20 74 6f 20 5c 63 6f 64 |defaults| to \cod|
|00002d90| 65 7b 27 72 27 7d 2e 0d | 54 68 65 20 6f 70 74 69 |e{'r'}..|The opti|
|00002da0| 6f 6e 61 6c 20 5c 76 61 | 72 7b 62 75 66 73 69 7a |onal \va|r{bufsiz|
|00002db0| 65 7d 20 61 72 67 75 6d | 65 6e 74 20 73 70 65 63 |e} argum|ent spec|
|00002dc0| 69 66 69 65 73 20 74 68 | 65 20 66 69 6c 65 27 73 |ifies th|e file's|
|00002dd0| 20 64 65 73 69 72 65 64 | 0d 62 75 66 66 65 72 20 | desired|.buffer |
|00002de0| 73 69 7a 65 3a 20 30 20 | 6d 65 61 6e 73 20 75 6e |size: 0 |means un|
|00002df0| 62 75 66 66 65 72 65 64 | 2c 20 31 20 6d 65 61 6e |buffered|, 1 mean|
|00002e00| 73 20 6c 69 6e 65 20 62 | 75 66 66 65 72 65 64 2c |s line b|uffered,|
|00002e10| 20 61 6e 79 20 6f 74 68 | 65 72 0d 70 6f 73 69 74 | any oth|er.posit|
|00002e20| 69 76 65 20 76 61 6c 75 | 65 20 6d 65 61 6e 73 20 |ive valu|e means |
|00002e30| 75 73 65 20 61 20 62 75 | 66 66 65 72 20 6f 66 20 |use a bu|ffer of |
|00002e40| 28 61 70 70 72 6f 78 69 | 6d 61 74 65 6c 79 29 20 |(approxi|mately) |
|00002e50| 74 68 61 74 20 73 69 7a | 65 2e 20 20 41 0d 6e 65 |that siz|e. A.ne|
|00002e60| 67 61 74 69 76 65 20 5c | 76 61 72 7b 62 75 66 73 |gative \|var{bufs|
|00002e70| 69 7a 65 7d 20 6d 65 61 | 6e 73 20 74 6f 20 75 73 |ize} mea|ns to us|
|00002e80| 65 20 74 68 65 20 73 79 | 73 74 65 6d 20 64 65 66 |e the sy|stem def|
|00002e90| 61 75 6c 74 2c 20 77 68 | 69 63 68 20 69 73 0d 75 |ault, wh|ich is.u|
|00002ea0| 73 75 61 6c 6c 79 20 6c | 69 6e 65 20 62 75 66 66 |sually l|ine buff|
|00002eb0| 65 72 65 64 20 66 6f 72 | 20 66 6f 72 20 74 74 79 |ered for| for tty|
|00002ec0| 20 64 65 76 69 63 65 73 | 20 61 6e 64 20 66 75 6c | devices| and ful|
|00002ed0| 6c 79 20 62 75 66 66 65 | 72 65 64 20 66 6f 72 20 |ly buffe|red for |
|00002ee0| 6f 74 68 65 72 0d 66 69 | 6c 65 73 2e 25 0d 5c 66 |other.fi|les.%.\f|
|00002ef0| 6f 6f 74 6e 6f 74 65 7b | 53 70 65 63 69 66 79 69 |ootnote{|Specifyi|
|00002f00| 6e 67 20 61 20 62 75 66 | 66 65 72 20 73 69 7a 65 |ng a buf|fer size|
|00002f10| 20 63 75 72 72 65 6e 74 | 6c 79 20 68 61 73 20 6e | current|ly has n|
|00002f20| 6f 20 65 66 66 65 63 74 | 20 6f 6e 20 73 79 73 74 |o effect| on syst|
|00002f30| 65 6d 73 0d 74 68 61 74 | 20 64 6f 6e 27 74 20 68 |ems.that| don't h|
|00002f40| 61 76 65 20 5c 63 6f 64 | 65 7b 73 65 74 76 62 75 |ave \cod|e{setvbu|
|00002f50| 66 28 29 7d 2e 20 20 54 | 68 65 20 69 6e 74 65 72 |f()}. T|he inter|
|00002f60| 66 61 63 65 20 74 6f 20 | 73 70 65 63 69 66 79 20 |face to |specify |
|00002f70| 74 68 65 20 62 75 66 66 | 65 72 0d 73 69 7a 65 20 |the buff|er.size |
|00002f80| 69 73 20 6e 6f 74 20 64 | 6f 6e 65 20 75 73 69 6e |is not d|one usin|
|00002f90| 67 20 61 20 6d 65 74 68 | 6f 64 20 74 68 61 74 20 |g a meth|od that |
|00002fa0| 63 61 6c 6c 73 20 5c 63 | 6f 64 65 7b 73 65 74 76 |calls \c|ode{setv|
|00002fb0| 62 75 66 28 29 7d 2c 20 | 62 65 63 61 75 73 65 0d |buf()}, |because.|
|00002fc0| 74 68 61 74 20 6d 61 79 | 20 64 75 6d 70 20 63 6f |that may| dump co|
|00002fd0| 72 65 20 77 68 65 6e 20 | 63 61 6c 6c 65 64 20 61 |re when |called a|
|00002fe0| 66 74 65 72 20 61 6e 79 | 20 49 2f 4f 20 68 61 73 |fter any| I/O has|
|00002ff0| 20 62 65 65 6e 20 70 65 | 72 66 6f 72 6d 65 64 2c | been pe|rformed,|
|00003000| 20 61 6e 64 0d 74 68 65 | 72 65 27 73 20 6e 6f 20 | and.the|re's no |
|00003010| 72 65 6c 69 61 62 6c 65 | 20 77 61 79 20 74 6f 20 |reliable| way to |
|00003020| 64 65 74 65 72 6d 69 6e | 65 20 77 68 65 74 68 65 |determin|e whethe|
|00003030| 72 20 74 68 69 73 20 69 | 73 20 74 68 65 20 63 61 |r this i|s the ca|
|00003040| 73 65 2e 7d 0d 5c 65 6e | 64 7b 66 75 6e 63 64 65 |se.}.\en|d{funcde|
|00003050| 73 63 7d 0d 0d 5c 62 65 | 67 69 6e 7b 66 75 6e 63 |sc}..\be|gin{func|
|00003060| 64 65 73 63 7d 7b 6f 72 | 64 7d 7b 63 7d 0d 20 20 |desc}{or|d}{c}. |
|00003070| 52 65 74 75 72 6e 20 74 | 68 65 20 5c 41 53 43 49 |Return t|he \ASCI|
|00003080| 49 7b 7d 20 76 61 6c 75 | 65 20 6f 66 20 61 20 73 |I{} valu|e of a s|
|00003090| 74 72 69 6e 67 20 6f 66 | 20 6f 6e 65 20 63 68 61 |tring of| one cha|
|000030a0| 72 61 63 74 65 72 2e 20 | 20 45 2e 67 2e 2c 0d 20 |racter. | E.g.,. |
|000030b0| 20 5c 63 6f 64 65 7b 6f | 72 64 28 27 61 27 29 7d | \code{o|rd('a')}|
|000030c0| 20 72 65 74 75 72 6e 73 | 20 74 68 65 20 69 6e 74 | returns| the int|
|000030d0| 65 67 65 72 20 5c 63 6f | 64 65 7b 39 37 7d 2e 20 |eger \co|de{97}. |
|000030e0| 20 54 68 69 73 20 69 73 | 20 74 68 65 20 69 6e 76 | This is| the inv|
|000030f0| 65 72 73 65 20 6f 66 0d | 20 20 5c 63 6f 64 65 7b |erse of.| \code{|
|00003100| 63 68 72 28 29 7d 2e 0d | 5c 65 6e 64 7b 66 75 6e |chr()}..|\end{fun|
|00003110| 63 64 65 73 63 7d 0d 0d | 5c 62 65 67 69 6e 7b 66 |cdesc}..|\begin{f|
|00003120| 75 6e 63 64 65 73 63 7d | 7b 70 6f 77 7d 7b 78 5c |uncdesc}|{pow}{x\|
|00003130| 2c 20 79 5c 6f 70 74 69 | 6f 6e 61 6c 7b 5c 2c 20 |, y\opti|onal{\, |
|00003140| 7a 7d 7d 0d 20 20 52 65 | 74 75 72 6e 20 5c 76 61 |z}}. Re|turn \va|
|00003150| 72 7b 78 7d 20 74 6f 20 | 74 68 65 20 70 6f 77 65 |r{x} to |the powe|
|00003160| 72 20 5c 76 61 72 7b 79 | 7d 3b 20 69 66 20 5c 76 |r \var{y|}; if \v|
|00003170| 61 72 7b 7a 7d 20 69 73 | 20 70 72 65 73 65 6e 74 |ar{z} is| present|
|00003180| 2c 20 72 65 74 75 72 6e | 0d 20 20 5c 76 61 72 7b |, return|. \var{|
|00003190| 78 7d 20 74 6f 20 74 68 | 65 20 70 6f 77 65 72 20 |x} to th|e power |
|000031a0| 5c 76 61 72 7b 79 7d 2c | 20 6d 6f 64 75 6c 6f 20 |\var{y},| modulo |
|000031b0| 5c 76 61 72 7b 7a 7d 20 | 28 63 6f 6d 70 75 74 65 |\var{z} |(compute|
|000031c0| 64 20 6d 6f 72 65 0d 20 | 20 65 66 66 69 63 69 65 |d more. | efficie|
|000031d0| 6e 74 6c 79 20 74 68 61 | 6e 20 5c 63 6f 64 65 7b |ntly tha|n \code{|
|000031e0| 70 6f 77 28 5c 76 61 72 | 7b 78 7d 2c 20 5c 76 61 |pow(\var|{x}, \va|
|000031f0| 72 7b 79 7d 29 20 5c 25 | 20 5c 76 61 72 7b 7a 7d |r{y}) \%| \var{z}|
|00003200| 7d 29 2e 0d 20 20 54 68 | 65 20 61 72 67 75 6d 65 |}).. Th|e argume|
|00003210| 6e 74 73 20 6d 75 73 74 | 20 68 61 76 65 0d 20 20 |nts must| have. |
|00003220| 6e 75 6d 65 72 69 63 20 | 74 79 70 65 73 2e 20 20 |numeric |types. |
|00003230| 57 69 74 68 20 6d 69 78 | 65 64 20 6f 70 65 72 61 |With mix|ed opera|
|00003240| 6e 64 20 74 79 70 65 73 | 2c 20 74 68 65 20 72 75 |nd types|, the ru|
|00003250| 6c 65 73 20 66 6f 72 20 | 62 69 6e 61 72 79 0d 20 |les for |binary. |
|00003260| 20 61 72 69 74 68 6d 65 | 74 69 63 20 6f 70 65 72 | arithme|tic oper|
|00003270| 61 74 6f 72 73 20 61 70 | 70 6c 79 2e 20 20 54 68 |ators ap|ply. Th|
|00003280| 65 20 65 66 66 65 63 74 | 69 76 65 20 6f 70 65 72 |e effect|ive oper|
|00003290| 61 6e 64 20 74 79 70 65 | 20 69 73 20 61 6c 73 6f |and type| is also|
|000032a0| 20 74 68 65 0d 20 20 74 | 79 70 65 20 6f 66 20 74 | the. t|ype of t|
|000032b0| 68 65 20 72 65 73 75 6c | 74 3b 20 69 66 20 74 68 |he resul|t; if th|
|000032c0| 65 20 72 65 73 75 6c 74 | 20 69 73 20 6e 6f 74 20 |e result| is not |
|000032d0| 65 78 70 72 65 73 73 69 | 62 6c 65 20 69 6e 20 74 |expressi|ble in t|
|000032e0| 68 69 73 20 74 79 70 65 | 2c 20 74 68 65 0d 20 20 |his type|, the. |
|000032f0| 66 75 6e 63 74 69 6f 6e | 20 72 61 69 73 65 73 20 |function| raises |
|00003300| 61 6e 20 65 78 63 65 70 | 74 69 6f 6e 3b 20 65 2e |an excep|tion; e.|
|00003310| 67 2e 2c 20 5c 63 6f 64 | 65 7b 70 6f 77 28 32 2c |g., \cod|e{pow(2,|
|00003320| 20 2d 31 29 7d 20 6f 72 | 20 5c 63 6f 64 65 7b 70 | -1)} or| \code{p|
|00003330| 6f 77 28 32 2c 0d 20 20 | 33 35 30 30 30 29 7d 20 |ow(2,. |35000)} |
|00003340| 69 73 20 6e 6f 74 20 61 | 6c 6c 6f 77 65 64 2e 0d |is not a|llowed..|
|00003350| 5c 65 6e 64 7b 66 75 6e | 63 64 65 73 63 7d 0d 0d |\end{fun|cdesc}..|
|00003360| 5c 62 65 67 69 6e 7b 66 | 75 6e 63 64 65 73 63 7d |\begin{f|uncdesc}|
|00003370| 7b 72 61 6e 67 65 7d 7b | 5c 6f 70 74 69 6f 6e 61 |{range}{|\optiona|
|00003380| 6c 7b 73 74 61 72 74 5c | 2c 7d 20 65 6e 64 5c 6f |l{start\|,} end\o|
|00003390| 70 74 69 6f 6e 61 6c 7b | 5c 2c 20 73 74 65 70 7d |ptional{|\, step}|
|000033a0| 7d 0d 20 20 54 68 69 73 | 20 69 73 20 61 20 76 65 |}. This| is a ve|
|000033b0| 72 73 61 74 69 6c 65 20 | 66 75 6e 63 74 69 6f 6e |rsatile |function|
|000033c0| 20 74 6f 20 63 72 65 61 | 74 65 20 6c 69 73 74 73 | to crea|te lists|
|000033d0| 20 63 6f 6e 74 61 69 6e | 69 6e 67 20 61 72 69 74 | contain|ing arit|
|000033e0| 68 6d 65 74 69 63 0d 20 | 20 70 72 6f 67 72 65 73 |hmetic. | progres|
|000033f0| 73 69 6f 6e 73 2e 20 20 | 49 74 20 69 73 20 6d 6f |sions. |It is mo|
|00003400| 73 74 20 6f 66 74 65 6e | 20 75 73 65 64 20 69 6e |st often| used in|
|00003410| 20 5c 63 6f 64 65 7b 66 | 6f 72 7d 20 6c 6f 6f 70 | \code{f|or} loop|
|00003420| 73 2e 20 20 54 68 65 0d | 20 20 61 72 67 75 6d 65 |s. The.| argume|
|00003430| 6e 74 73 20 6d 75 73 74 | 20 62 65 20 70 6c 61 69 |nts must| be plai|
|00003440| 6e 20 69 6e 74 65 67 65 | 72 73 2e 20 20 49 66 20 |n intege|rs. If |
|00003450| 74 68 65 20 5c 76 61 72 | 7b 73 74 65 70 7d 20 61 |the \var|{step} a|
|00003460| 72 67 75 6d 65 6e 74 20 | 69 73 0d 20 20 6f 6d 69 |rgument |is. omi|
|00003470| 74 74 65 64 2c 20 69 74 | 20 64 65 66 61 75 6c 74 |tted, it| default|
|00003480| 73 20 74 6f 20 5c 63 6f | 64 65 7b 31 7d 2e 20 20 |s to \co|de{1}. |
|00003490| 49 66 20 74 68 65 20 5c | 76 61 72 7b 73 74 61 72 |If the \|var{star|
|000034a0| 74 7d 20 61 72 67 75 6d | 65 6e 74 20 69 73 0d 20 |t} argum|ent is. |
|000034b0| 20 6f 6d 69 74 74 65 64 | 2c 20 69 74 20 64 65 66 | omitted|, it def|
|000034c0| 61 75 6c 74 73 20 74 6f | 20 5c 63 6f 64 65 7b 30 |aults to| \code{0|
|000034d0| 7d 2e 20 20 54 68 65 20 | 66 75 6c 6c 20 66 6f 72 |}. The |full for|
|000034e0| 6d 20 72 65 74 75 72 6e | 73 20 61 20 6c 69 73 74 |m return|s a list|
|000034f0| 20 6f 66 0d 20 20 70 6c | 61 69 6e 20 69 6e 74 65 | of. pl|ain inte|
|00003500| 67 65 72 73 20 5c 63 6f | 64 65 7b 5b 5c 76 61 72 |gers \co|de{[\var|
|00003510| 7b 73 74 61 72 74 7d 2c | 20 5c 76 61 72 7b 73 74 |{start},| \var{st|
|00003520| 61 72 74 7d 20 2b 20 5c | 76 61 72 7b 73 74 65 70 |art} + \|var{step|
|00003530| 7d 2c 0d 20 20 5c 76 61 | 72 7b 73 74 61 72 74 7d |},. \va|r{start}|
|00003540| 20 2b 20 32 20 2a 20 5c | 76 61 72 7b 73 74 65 70 | + 2 * \|var{step|
|00003550| 7d 2c 20 5c 6c 64 6f 74 | 73 5d 7d 2e 20 20 49 66 |}, \ldot|s]}. If|
|00003560| 20 5c 76 61 72 7b 73 74 | 65 70 7d 20 69 73 20 70 | \var{st|ep} is p|
|00003570| 6f 73 69 74 69 76 65 2c | 0d 20 20 74 68 65 20 6c |ositive,|. the l|
|00003580| 61 73 74 20 65 6c 65 6d | 65 6e 74 20 69 73 20 74 |ast elem|ent is t|
|00003590| 68 65 20 6c 61 72 67 65 | 73 74 20 5c 63 6f 64 65 |he large|st \code|
|000035a0| 7b 5c 76 61 72 7b 73 74 | 61 72 74 7d 20 2b 20 5c |{\var{st|art} + \|
|000035b0| 76 61 72 7b 69 7d 20 2a | 0d 20 20 5c 76 61 72 7b |var{i} *|. \var{|
|000035c0| 73 74 65 70 7d 7d 20 6c | 65 73 73 20 74 68 61 6e |step}} l|ess than|
|000035d0| 20 5c 76 61 72 7b 65 6e | 64 7d 3b 20 69 66 20 5c | \var{en|d}; if \|
|000035e0| 76 61 72 7b 73 74 65 70 | 7d 20 69 73 20 6e 65 67 |var{step|} is neg|
|000035f0| 61 74 69 76 65 2c 20 74 | 68 65 20 6c 61 73 74 0d |ative, t|he last.|
|00003600| 20 20 65 6c 65 6d 65 6e | 74 20 69 73 20 74 68 65 | elemen|t is the|
|00003610| 20 6c 61 72 67 65 73 74 | 20 5c 63 6f 64 65 7b 5c | largest| \code{\|
|00003620| 76 61 72 7b 73 74 61 72 | 74 7d 20 2b 20 5c 76 61 |var{star|t} + \va|
|00003630| 72 7b 69 7d 20 2a 20 5c | 76 61 72 7b 73 74 65 70 |r{i} * \|var{step|
|00003640| 7d 7d 0d 20 20 67 72 65 | 61 74 65 72 20 74 68 61 |}}. gre|ater tha|
|00003650| 6e 20 5c 76 61 72 7b 65 | 6e 64 7d 2e 20 20 5c 76 |n \var{e|nd}. \v|
|00003660| 61 72 7b 73 74 65 70 7d | 20 6d 75 73 74 20 6e 6f |ar{step}| must no|
|00003670| 74 20 62 65 20 7a 65 72 | 6f 20 28 6f 72 20 65 6c |t be zer|o (or el|
|00003680| 73 65 20 61 6e 0d 20 20 | 65 78 63 65 70 74 69 6f |se an. |exceptio|
|00003690| 6e 20 69 73 20 72 61 69 | 73 65 64 29 2e 20 20 45 |n is rai|sed). E|
|000036a0| 78 61 6d 70 6c 65 3a 0d | 0d 5c 62 63 6f 64 65 5c |xample:.|.\bcode\|
|000036b0| 62 65 67 69 6e 7b 76 65 | 72 62 61 74 69 6d 7d 0d |begin{ve|rbatim}.|
|000036c0| 3e 3e 3e 20 72 61 6e 67 | 65 28 31 30 29 0d 5b 30 |>>> rang|e(10).[0|
|000036d0| 2c 20 31 2c 20 32 2c 20 | 33 2c 20 34 2c 20 35 2c |, 1, 2, |3, 4, 5,|
|000036e0| 20 36 2c 20 37 2c 20 38 | 2c 20 39 5d 0d 3e 3e 3e | 6, 7, 8|, 9].>>>|
|000036f0| 20 72 61 6e 67 65 28 31 | 2c 20 31 31 29 0d 5b 31 | range(1|, 11).[1|
|00003700| 2c 20 32 2c 20 33 2c 20 | 34 2c 20 35 2c 20 36 2c |, 2, 3, |4, 5, 6,|
|00003710| 20 37 2c 20 38 2c 20 39 | 2c 20 31 30 5d 0d 3e 3e | 7, 8, 9|, 10].>>|
|00003720| 3e 20 72 61 6e 67 65 28 | 30 2c 20 33 30 2c 20 35 |> range(|0, 30, 5|
|00003730| 29 0d 5b 30 2c 20 35 2c | 20 31 30 2c 20 31 35 2c |).[0, 5,| 10, 15,|
|00003740| 20 32 30 2c 20 32 35 5d | 0d 3e 3e 3e 20 72 61 6e | 20, 25]|.>>> ran|
|00003750| 67 65 28 30 2c 20 31 30 | 2c 20 33 29 0d 5b 30 2c |ge(0, 10|, 3).[0,|
|00003760| 20 33 2c 20 36 2c 20 39 | 5d 0d 3e 3e 3e 20 72 61 | 3, 6, 9|].>>> ra|
|00003770| 6e 67 65 28 30 2c 20 2d | 31 30 2c 20 2d 31 29 0d |nge(0, -|10, -1).|
|00003780| 5b 30 2c 20 2d 31 2c 20 | 2d 32 2c 20 2d 33 2c 20 |[0, -1, |-2, -3, |
|00003790| 2d 34 2c 20 2d 35 2c 20 | 2d 36 2c 20 2d 37 2c 20 |-4, -5, |-6, -7, |
|000037a0| 2d 38 2c 20 2d 39 5d 0d | 3e 3e 3e 20 72 61 6e 67 |-8, -9].|>>> rang|
|000037b0| 65 28 30 29 0d 5b 5d 0d | 3e 3e 3e 20 72 61 6e 67 |e(0).[].|>>> rang|
|000037c0| 65 28 31 2c 20 30 29 0d | 5b 5d 0d 3e 3e 3e 20 0d |e(1, 0).|[].>>> .|
|000037d0| 5c 65 6e 64 7b 76 65 72 | 62 61 74 69 6d 7d 5c 65 |\end{ver|batim}\e|
|000037e0| 63 6f 64 65 0d 5c 65 6e | 64 7b 66 75 6e 63 64 65 |code.\en|d{funcde|
|000037f0| 73 63 7d 0d 0d 5c 62 65 | 67 69 6e 7b 66 75 6e 63 |sc}..\be|gin{func|
|00003800| 64 65 73 63 7d 7b 72 61 | 77 5f 69 6e 70 75 74 7d |desc}{ra|w_input}|
|00003810| 7b 5c 6f 70 74 69 6f 6e | 61 6c 7b 70 72 6f 6d 70 |{\option|al{promp|
|00003820| 74 7d 7d 0d 20 20 49 66 | 20 74 68 65 20 5c 76 61 |t}}. If| the \va|
|00003830| 72 7b 70 72 6f 6d 70 74 | 7d 20 61 72 67 75 6d 65 |r{prompt|} argume|
|00003840| 6e 74 20 69 73 20 70 72 | 65 73 65 6e 74 2c 20 69 |nt is pr|esent, i|
|00003850| 74 20 69 73 20 77 72 69 | 74 74 65 6e 20 74 6f 20 |t is wri|tten to |
|00003860| 73 74 61 6e 64 61 72 64 | 20 6f 75 74 70 75 74 0d |standard| output.|
|00003870| 20 20 77 69 74 68 6f 75 | 74 20 61 20 74 72 61 69 | withou|t a trai|
|00003880| 6c 69 6e 67 20 6e 65 77 | 6c 69 6e 65 2e 20 20 54 |ling new|line. T|
|00003890| 68 65 20 66 75 6e 63 74 | 69 6f 6e 20 74 68 65 6e |he funct|ion then|
|000038a0| 20 72 65 61 64 73 20 61 | 20 6c 69 6e 65 20 66 72 | reads a| line fr|
|000038b0| 6f 6d 20 69 6e 70 75 74 | 2c 0d 20 20 63 6f 6e 76 |om input|,. conv|
|000038c0| 65 72 74 73 20 69 74 20 | 74 6f 20 61 20 73 74 72 |erts it |to a str|
|000038d0| 69 6e 67 20 28 73 74 72 | 69 70 70 69 6e 67 20 61 |ing (str|ipping a|
|000038e0| 20 74 72 61 69 6c 69 6e | 67 20 6e 65 77 6c 69 6e | trailin|g newlin|
|000038f0| 65 29 2c 20 61 6e 64 20 | 72 65 74 75 72 6e 73 20 |e), and |returns |
|00003900| 74 68 61 74 2e 0d 20 20 | 57 68 65 6e 20 5c 45 4f |that.. |When \EO|
|00003910| 46 7b 7d 20 69 73 20 72 | 65 61 64 2c 20 5c 63 6f |F{} is r|ead, \co|
|00003920| 64 65 7b 45 4f 46 45 72 | 72 6f 72 7d 20 69 73 20 |de{EOFEr|ror} is |
|00003930| 72 61 69 73 65 64 2e 20 | 45 78 61 6d 70 6c 65 3a |raised. |Example:|
|00003940| 0d 0d 5c 62 63 6f 64 65 | 5c 62 65 67 69 6e 7b 76 |..\bcode|\begin{v|
|00003950| 65 72 62 61 74 69 6d 7d | 0d 3e 3e 3e 20 73 20 3d |erbatim}|.>>> s =|
|00003960| 20 72 61 77 5f 69 6e 70 | 75 74 28 27 2d 2d 3e 20 | raw_inp|ut('--> |
|00003970| 27 29 0d 2d 2d 3e 20 4d | 6f 6e 74 79 20 50 79 74 |').--> M|onty Pyt|
|00003980| 68 6f 6e 27 73 20 46 6c | 79 69 6e 67 20 43 69 72 |hon's Fl|ying Cir|
|00003990| 63 75 73 0d 3e 3e 3e 20 | 73 0d 22 4d 6f 6e 74 79 |cus.>>> |s."Monty|
|000039a0| 20 50 79 74 68 6f 6e 27 | 73 20 46 6c 79 69 6e 67 | Python'|s Flying|
|000039b0| 20 43 69 72 63 75 73 22 | 0d 3e 3e 3e 20 0d 5c 65 | Circus"|.>>> .\e|
|000039c0| 6e 64 7b 76 65 72 62 61 | 74 69 6d 7d 5c 65 63 6f |nd{verba|tim}\eco|
|000039d0| 64 65 0d 5c 65 6e 64 7b | 66 75 6e 63 64 65 73 63 |de.\end{|funcdesc|
|000039e0| 7d 0d 0d 5c 62 65 67 69 | 6e 7b 66 75 6e 63 64 65 |}..\begi|n{funcde|
|000039f0| 73 63 7d 7b 72 65 64 75 | 63 65 7d 7b 66 75 6e 63 |sc}{redu|ce}{func|
|00003a00| 74 69 6f 6e 5c 2c 20 6c | 69 73 74 5c 6f 70 74 69 |tion\, l|ist\opti|
|00003a10| 6f 6e 61 6c 7b 5c 2c 20 | 69 6e 69 74 69 61 6c 69 |onal{\, |initiali|
|00003a20| 7a 65 72 7d 7d 0d 41 70 | 70 6c 79 20 74 68 65 20 |zer}}.Ap|ply the |
|00003a30| 62 69 6e 61 72 79 20 5c | 76 61 72 7b 66 75 6e 63 |binary \|var{func|
|00003a40| 74 69 6f 6e 7d 20 74 6f | 20 74 68 65 20 69 74 65 |tion} to| the ite|
|00003a50| 6d 73 20 6f 66 20 5c 76 | 61 72 7b 6c 69 73 74 7d |ms of \v|ar{list}|
|00003a60| 20 73 6f 20 61 73 20 74 | 6f 0d 72 65 64 75 63 65 | so as t|o.reduce|
|00003a70| 20 74 68 65 20 6c 69 73 | 74 20 74 6f 20 61 20 73 | the lis|t to a s|
|00003a80| 69 6e 67 6c 65 20 76 61 | 6c 75 65 2e 20 20 45 2e |ingle va|lue. E.|
|00003a90| 67 2e 2c 0d 5c 63 6f 64 | 65 7b 72 65 64 75 63 65 |g.,.\cod|e{reduce|
|00003aa0| 28 6c 61 6d 62 64 61 20 | 78 2c 20 79 3a 20 78 2a |(lambda |x, y: x*|
|00003ab0| 79 2c 20 5c 76 61 72 7b | 6c 69 73 74 7d 2c 20 31 |y, \var{|list}, 1|
|00003ac0| 29 7d 20 72 65 74 75 72 | 6e 73 20 74 68 65 20 70 |)} retur|ns the p|
|00003ad0| 72 6f 64 75 63 74 20 6f | 66 0d 74 68 65 20 65 6c |roduct o|f.the el|
|00003ae0| 65 6d 65 6e 74 73 20 6f | 66 20 5c 76 61 72 7b 6c |ements o|f \var{l|
|00003af0| 69 73 74 7d 2e 20 20 54 | 68 65 20 6f 70 74 69 6f |ist}. T|he optio|
|00003b00| 6e 61 6c 20 5c 76 61 72 | 7b 69 6e 69 74 69 61 6c |nal \var|{initial|
|00003b10| 69 7a 65 72 7d 20 63 61 | 6e 20 62 65 0d 74 68 6f |izer} ca|n be.tho|
|00003b20| 75 67 68 74 20 6f 66 20 | 61 73 20 62 65 69 6e 67 |ught of |as being|
|00003b30| 20 70 72 65 70 65 6e 64 | 65 64 20 74 6f 20 5c 76 | prepend|ed to \v|
|00003b40| 61 72 7b 6c 69 73 74 7d | 20 73 6f 20 61 73 20 74 |ar{list}| so as t|
|00003b50| 6f 20 61 6c 6c 6f 77 20 | 72 65 64 75 63 74 69 6f |o allow |reductio|
|00003b60| 6e 0d 6f 66 20 61 6e 20 | 65 6d 70 74 79 20 5c 76 |n.of an |empty \v|
|00003b70| 61 72 7b 6c 69 73 74 7d | 2e 20 20 54 68 65 20 5c |ar{list}|. The \|
|00003b80| 76 61 72 7b 6c 69 73 74 | 7d 20 61 72 67 75 6d 65 |var{list|} argume|
|00003b90| 6e 74 73 20 6d 61 79 20 | 62 65 20 61 6e 79 20 6b |nts may |be any k|
|00003ba0| 69 6e 64 20 6f 66 0d 73 | 65 71 75 65 6e 63 65 2e |ind of.s|equence.|
|00003bb0| 0d 5c 65 6e 64 7b 66 75 | 6e 63 64 65 73 63 7d 0d |.\end{fu|ncdesc}.|
|00003bc0| 0d 5c 62 65 67 69 6e 7b | 66 75 6e 63 64 65 73 63 |.\begin{|funcdesc|
|00003bd0| 7d 7b 72 65 6c 6f 61 64 | 7d 7b 6d 6f 64 75 6c 65 |}{reload|}{module|
|00003be0| 7d 0d 52 65 2d 70 61 72 | 73 65 20 61 6e 64 20 72 |}.Re-par|se and r|
|00003bf0| 65 2d 69 6e 69 74 69 61 | 6c 69 7a 65 20 61 6e 20 |e-initia|lize an |
|00003c00| 61 6c 72 65 61 64 79 20 | 69 6d 70 6f 72 74 65 64 |already |imported|
|00003c10| 20 5c 76 61 72 7b 6d 6f | 64 75 6c 65 7d 2e 20 20 | \var{mo|dule}. |
|00003c20| 54 68 65 0d 61 72 67 75 | 6d 65 6e 74 20 6d 75 73 |The.argu|ment mus|
|00003c30| 74 20 62 65 20 61 20 6d | 6f 64 75 6c 65 20 6f 62 |t be a m|odule ob|
|00003c40| 6a 65 63 74 2c 20 73 6f | 20 69 74 20 6d 75 73 74 |ject, so| it must|
|00003c50| 20 68 61 76 65 20 62 65 | 65 6e 20 73 75 63 63 65 | have be|en succe|
|00003c60| 73 73 66 75 6c 6c 79 0d | 69 6d 70 6f 72 74 65 64 |ssfully.|imported|
|00003c70| 20 62 65 66 6f 72 65 2e | 20 20 54 68 69 73 20 69 | before.| This i|
|00003c80| 73 20 75 73 65 66 75 6c | 20 69 66 20 79 6f 75 20 |s useful| if you |
|00003c90| 68 61 76 65 20 65 64 69 | 74 65 64 20 74 68 65 20 |have edi|ted the |
|00003ca0| 6d 6f 64 75 6c 65 20 73 | 6f 75 72 63 65 0d 66 69 |module s|ource.fi|
|00003cb0| 6c 65 20 75 73 69 6e 67 | 20 61 6e 20 65 78 74 65 |le using| an exte|
|00003cc0| 72 6e 61 6c 20 65 64 69 | 74 6f 72 20 61 6e 64 20 |rnal edi|tor and |
|00003cd0| 77 61 6e 74 20 74 6f 20 | 74 72 79 20 6f 75 74 20 |want to |try out |
|00003ce0| 74 68 65 20 6e 65 77 20 | 76 65 72 73 69 6f 6e 0d |the new |version.|
|00003cf0| 77 69 74 68 6f 75 74 20 | 6c 65 61 76 69 6e 67 20 |without |leaving |
|00003d00| 74 68 65 20 50 79 74 68 | 6f 6e 20 69 6e 74 65 72 |the Pyth|on inter|
|00003d10| 70 72 65 74 65 72 2e 20 | 20 54 68 65 20 72 65 74 |preter. | The ret|
|00003d20| 75 72 6e 20 76 61 6c 75 | 65 20 69 73 20 74 68 65 |urn valu|e is the|
|00003d30| 0d 6d 6f 64 75 6c 65 20 | 6f 62 6a 65 63 74 20 28 |.module |object (|
|00003d40| 69 2e 65 2e 5c 20 74 68 | 65 20 73 61 6d 65 20 61 |i.e.\ th|e same a|
|00003d50| 73 20 74 68 65 20 5c 76 | 61 72 7b 6d 6f 64 75 6c |s the \v|ar{modul|
|00003d60| 65 7d 20 61 72 67 75 6d | 65 6e 74 29 2e 0d 0d 54 |e} argum|ent)...T|
|00003d70| 68 65 72 65 20 61 72 65 | 20 61 20 6e 75 6d 62 65 |here are| a numbe|
|00003d80| 72 20 6f 66 20 63 61 76 | 65 61 74 73 3a 0d 0d 49 |r of cav|eats:..I|
|00003d90| 66 20 61 20 6d 6f 64 75 | 6c 65 20 69 73 20 73 79 |f a modu|le is sy|
|00003da0| 6e 74 61 63 74 69 63 61 | 6c 6c 79 20 63 6f 72 72 |ntactica|lly corr|
|00003db0| 65 63 74 20 62 75 74 20 | 69 74 73 20 69 6e 69 74 |ect but |its init|
|00003dc0| 69 61 6c 69 7a 61 74 69 | 6f 6e 20 66 61 69 6c 73 |ializati|on fails|
|00003dd0| 2c 20 74 68 65 0d 66 69 | 72 73 74 20 5c 63 6f 64 |, the.fi|rst \cod|
|00003de0| 65 7b 69 6d 70 6f 72 74 | 7d 20 73 74 61 74 65 6d |e{import|} statem|
|00003df0| 65 6e 74 20 66 6f 72 20 | 69 74 20 64 6f 65 73 20 |ent for |it does |
|00003e00| 6e 6f 74 20 62 69 6e 64 | 20 69 74 73 20 6e 61 6d |not bind| its nam|
|00003e10| 65 20 6c 6f 63 61 6c 6c | 79 2c 0d 62 75 74 20 64 |e locall|y,.but d|
|00003e20| 6f 65 73 20 73 74 6f 72 | 65 20 61 20 28 70 61 72 |oes stor|e a (par|
|00003e30| 74 69 61 6c 6c 79 20 69 | 6e 69 74 69 61 6c 69 7a |tially i|nitializ|
|00003e40| 65 64 29 20 6d 6f 64 75 | 6c 65 20 6f 62 6a 65 63 |ed) modu|le objec|
|00003e50| 74 20 69 6e 0d 5c 63 6f | 64 65 7b 73 79 73 2e 6d |t in.\co|de{sys.m|
|00003e60| 6f 64 75 6c 65 73 7d 2e | 20 20 54 6f 20 72 65 6c |odules}.| To rel|
|00003e70| 6f 61 64 20 74 68 65 20 | 6d 6f 64 75 6c 65 20 79 |oad the |module y|
|00003e80| 6f 75 20 6d 75 73 74 20 | 66 69 72 73 74 0d 5c 63 |ou must |first.\c|
|00003e90| 6f 64 65 7b 69 6d 70 6f | 72 74 7d 20 69 74 20 61 |ode{impo|rt} it a|
|00003ea0| 67 61 69 6e 20 28 74 68 | 69 73 20 77 69 6c 6c 20 |gain (th|is will |
|00003eb0| 62 69 6e 64 20 74 68 65 | 20 6e 61 6d 65 20 74 6f |bind the| name to|
|00003ec0| 20 74 68 65 20 70 61 72 | 74 69 61 6c 6c 79 0d 69 | the par|tially.i|
|00003ed0| 6e 69 74 69 61 6c 69 7a | 65 64 20 6d 6f 64 75 6c |nitializ|ed modul|
|00003ee0| 65 20 6f 62 6a 65 63 74 | 29 20 62 65 66 6f 72 65 |e object|) before|
|00003ef0| 20 79 6f 75 20 63 61 6e | 20 5c 63 6f 64 65 7b 72 | you can| \code{r|
|00003f00| 65 6c 6f 61 64 28 29 7d | 20 69 74 2e 0d 0d 57 68 |eload()}| it...Wh|
|00003f10| 65 6e 20 61 20 6d 6f 64 | 75 6c 65 20 69 73 20 72 |en a mod|ule is r|
|00003f20| 65 6c 6f 61 64 65 64 2c | 20 69 74 73 20 64 69 63 |eloaded,| its dic|
|00003f30| 74 69 6f 6e 61 72 79 20 | 28 63 6f 6e 74 61 69 6e |tionary |(contain|
|00003f40| 69 6e 67 20 74 68 65 20 | 6d 6f 64 75 6c 65 27 73 |ing the |module's|
|00003f50| 0d 67 6c 6f 62 61 6c 20 | 76 61 72 69 61 62 6c 65 |.global |variable|
|00003f60| 73 29 20 69 73 20 72 65 | 74 61 69 6e 65 64 2e 20 |s) is re|tained. |
|00003f70| 20 52 65 64 65 66 69 6e | 69 74 69 6f 6e 73 20 6f | Redefin|itions o|
|00003f80| 66 20 6e 61 6d 65 73 20 | 77 69 6c 6c 20 6f 76 65 |f names |will ove|
|00003f90| 72 72 69 64 65 0d 74 68 | 65 20 6f 6c 64 20 64 65 |rride.th|e old de|
|00003fa0| 66 69 6e 69 74 69 6f 6e | 73 2c 20 73 6f 20 74 68 |finition|s, so th|
|00003fb0| 69 73 20 69 73 20 67 65 | 6e 65 72 61 6c 6c 79 20 |is is ge|nerally |
|00003fc0| 6e 6f 74 20 61 20 70 72 | 6f 62 6c 65 6d 2e 20 20 |not a pr|oblem. |
|00003fd0| 49 66 20 74 68 65 20 6e | 65 77 0d 76 65 72 73 69 |If the n|ew.versi|
|00003fe0| 6f 6e 20 6f 66 20 61 20 | 6d 6f 64 75 6c 65 20 64 |on of a |module d|
|00003ff0| 6f 65 73 20 6e 6f 74 20 | 64 65 66 69 6e 65 20 61 |oes not |define a|
|00004000| 20 6e 61 6d 65 20 74 68 | 61 74 20 77 61 73 20 64 | name th|at was d|
|00004010| 65 66 69 6e 65 64 20 62 | 79 20 74 68 65 20 6f 6c |efined b|y the ol|
|00004020| 64 0d 76 65 72 73 69 6f | 6e 2c 20 74 68 65 20 6f |d.versio|n, the o|
|00004030| 6c 64 20 64 65 66 69 6e | 69 74 69 6f 6e 20 72 65 |ld defin|ition re|
|00004040| 6d 61 69 6e 73 2e 20 20 | 54 68 69 73 20 66 65 61 |mains. |This fea|
|00004050| 74 75 72 65 20 63 61 6e | 20 62 65 20 75 73 65 64 |ture can| be used|
|00004060| 20 74 6f 20 74 68 65 0d | 6d 6f 64 75 6c 65 27 73 | to the.|module's|
|00004070| 20 61 64 76 61 6e 74 61 | 67 65 20 69 66 20 69 74 | advanta|ge if it|
|00004080| 20 6d 61 69 6e 74 61 69 | 6e 73 20 61 20 67 6c 6f | maintai|ns a glo|
|00004090| 62 61 6c 20 74 61 62 6c | 65 20 6f 72 20 63 61 63 |bal tabl|e or cac|
|000040a0| 68 65 20 6f 66 20 6f 62 | 6a 65 63 74 73 0d 2d 2d |he of ob|jects.--|
|000040b0| 2d 20 77 69 74 68 20 61 | 20 5c 63 6f 64 65 7b 74 |- with a| \code{t|
|000040c0| 72 79 7d 20 73 74 61 74 | 65 6d 65 6e 74 20 69 74 |ry} stat|ement it|
|000040d0| 20 63 61 6e 20 74 65 73 | 74 20 66 6f 72 20 74 68 | can tes|t for th|
|000040e0| 65 20 74 61 62 6c 65 27 | 73 20 70 72 65 73 65 6e |e table'|s presen|
|000040f0| 63 65 0d 61 6e 64 20 73 | 6b 69 70 20 69 74 73 20 |ce.and s|kip its |
|00004100| 69 6e 69 74 69 61 6c 69 | 7a 61 74 69 6f 6e 20 69 |initiali|zation i|
|00004110| 66 20 64 65 73 69 72 65 | 64 2e 0d 0d 49 74 20 69 |f desire|d...It i|
|00004120| 73 20 6c 65 67 61 6c 20 | 74 68 6f 75 67 68 20 67 |s legal |though g|
|00004130| 65 6e 65 72 61 6c 6c 79 | 20 6e 6f 74 20 76 65 72 |enerally| not ver|
|00004140| 79 20 75 73 65 66 75 6c | 20 74 6f 20 72 65 6c 6f |y useful| to relo|
|00004150| 61 64 20 62 75 69 6c 74 | 2d 69 6e 20 6f 72 0d 64 |ad built|-in or.d|
|00004160| 79 6e 61 6d 69 63 61 6c | 6c 79 20 6c 6f 61 64 65 |ynamical|ly loade|
|00004170| 64 20 6d 6f 64 75 6c 65 | 73 2c 20 65 78 63 65 70 |d module|s, excep|
|00004180| 74 20 66 6f 72 20 5c 63 | 6f 64 65 7b 73 79 73 7d |t for \c|ode{sys}|
|00004190| 2c 20 5c 63 6f 64 65 7b | 5f 5f 6d 61 69 6e 5f 5f |, \code{|__main__|
|000041a0| 7d 20 61 6e 64 0d 5c 63 | 6f 64 65 7b 5f 5f 62 75 |} and.\c|ode{__bu|
|000041b0| 69 6c 74 69 6e 5f 5f 7d | 2e 20 20 49 6e 20 63 65 |iltin__}|. In ce|
|000041c0| 72 74 61 69 6e 20 63 61 | 73 65 73 2c 20 68 6f 77 |rtain ca|ses, how|
|000041d0| 65 76 65 72 2c 20 65 78 | 74 65 6e 73 69 6f 6e 20 |ever, ex|tension |
|000041e0| 6d 6f 64 75 6c 65 73 20 | 61 72 65 0d 6e 6f 74 20 |modules |are.not |
|000041f0| 64 65 73 69 67 6e 65 64 | 20 74 6f 20 62 65 20 69 |designed| to be i|
|00004200| 6e 69 74 69 61 6c 69 7a | 65 64 20 6d 6f 72 65 20 |nitializ|ed more |
|00004210| 74 68 61 6e 20 6f 6e 63 | 65 2c 20 61 6e 64 20 6d |than onc|e, and m|
|00004220| 61 79 20 66 61 69 6c 20 | 69 6e 0d 61 72 62 69 74 |ay fail |in.arbit|
|00004230| 72 61 72 79 20 77 61 79 | 73 20 77 68 65 6e 20 72 |rary way|s when r|
|00004240| 65 6c 6f 61 64 65 64 2e | 0d 0d 49 66 20 61 20 6d |eloaded.|..If a m|
|00004250| 6f 64 75 6c 65 20 69 6d | 70 6f 72 74 73 20 6f 62 |odule im|ports ob|
|00004260| 6a 65 63 74 73 20 66 72 | 6f 6d 20 61 6e 6f 74 68 |jects fr|om anoth|
|00004270| 65 72 20 6d 6f 64 75 6c | 65 20 75 73 69 6e 67 20 |er modul|e using |
|00004280| 5c 63 6f 64 65 7b 66 72 | 6f 6d 7d 0d 7b 5c 6c 64 |\code{fr|om}.{\ld|
|00004290| 6f 74 73 7d 20 5c 63 6f | 64 65 7b 69 6d 70 6f 72 |ots} \co|de{impor|
|000042a0| 74 7d 20 7b 5c 6c 64 6f | 74 73 7d 2c 20 63 61 6c |t} {\ldo|ts}, cal|
|000042b0| 6c 69 6e 67 20 5c 63 6f | 64 65 7b 72 65 6c 6f 61 |ling \co|de{reloa|
|000042c0| 64 28 29 7d 20 66 6f 72 | 20 74 68 65 20 6f 74 68 |d()} for| the oth|
|000042d0| 65 72 0d 6d 6f 64 75 6c | 65 20 64 6f 65 73 20 6e |er.modul|e does n|
|000042e0| 6f 74 20 72 65 64 65 66 | 69 6e 65 20 74 68 65 20 |ot redef|ine the |
|000042f0| 6f 62 6a 65 63 74 73 20 | 69 6d 70 6f 72 74 65 64 |objects |imported|
|00004300| 20 66 72 6f 6d 20 69 74 | 20 2d 2d 2d 20 6f 6e 65 | from it| --- one|
|00004310| 20 77 61 79 0d 61 72 6f | 75 6e 64 20 74 68 69 73 | way.aro|und this|
|00004320| 20 69 73 20 74 6f 20 72 | 65 2d 65 78 65 63 75 74 | is to r|e-execut|
|00004330| 65 20 74 68 65 20 5c 63 | 6f 64 65 7b 66 72 6f 6d |e the \c|ode{from|
|00004340| 7d 20 73 74 61 74 65 6d | 65 6e 74 2c 20 61 6e 6f |} statem|ent, ano|
|00004350| 74 68 65 72 20 69 73 20 | 74 6f 0d 75 73 65 20 5c |ther is |to.use \|
|00004360| 63 6f 64 65 7b 69 6d 70 | 6f 72 74 7d 20 61 6e 64 |code{imp|ort} and|
|00004370| 20 71 75 61 6c 69 66 69 | 65 64 20 6e 61 6d 65 73 | qualifi|ed names|
|00004380| 20 28 5c 76 61 72 7b 6d | 6f 64 75 6c 65 7d 2e 5c | (\var{m|odule}.\|
|00004390| 76 61 72 7b 6e 61 6d 65 | 7d 29 0d 69 6e 73 74 65 |var{name|}).inste|
|000043a0| 61 64 2e 0d 0d 49 66 20 | 61 20 6d 6f 64 75 6c 65 |ad...If |a module|
|000043b0| 20 69 6e 73 74 61 6e 74 | 69 61 74 65 73 20 69 6e | instant|iates in|
|000043c0| 73 74 61 6e 63 65 73 20 | 6f 66 20 61 20 63 6c 61 |stances |of a cla|
|000043d0| 73 73 2c 20 72 65 6c 6f | 61 64 69 6e 67 20 74 68 |ss, relo|ading th|
|000043e0| 65 20 6d 6f 64 75 6c 65 | 0d 74 68 61 74 20 64 65 |e module|.that de|
|000043f0| 66 69 6e 65 73 20 74 68 | 65 20 63 6c 61 73 73 20 |fines th|e class |
|00004400| 64 6f 65 73 20 6e 6f 74 | 20 61 66 66 65 63 74 20 |does not| affect |
|00004410| 74 68 65 20 6d 65 74 68 | 6f 64 20 64 65 66 69 6e |the meth|od defin|
|00004420| 69 74 69 6f 6e 73 20 6f | 66 20 74 68 65 0d 69 6e |itions o|f the.in|
|00004430| 73 74 61 6e 63 65 73 20 | 2d 2d 2d 20 74 68 65 79 |stances |--- they|
|00004440| 20 63 6f 6e 74 69 6e 75 | 65 20 74 6f 20 75 73 65 | continu|e to use|
|00004450| 20 74 68 65 20 6f 6c 64 | 20 63 6c 61 73 73 20 64 | the old| class d|
|00004460| 65 66 69 6e 69 74 69 6f | 6e 2e 20 20 54 68 65 20 |efinitio|n. The |
|00004470| 73 61 6d 65 0d 69 73 20 | 74 72 75 65 20 66 6f 72 |same.is |true for|
|00004480| 20 64 65 72 69 76 65 64 | 20 63 6c 61 73 73 65 73 | derived| classes|
|00004490| 2e 0d 5c 65 6e 64 7b 66 | 75 6e 63 64 65 73 63 7d |..\end{f|uncdesc}|
|000044a0| 0d 0d 5c 62 65 67 69 6e | 7b 66 75 6e 63 64 65 73 |..\begin|{funcdes|
|000044b0| 63 7d 7b 72 65 70 72 7d | 7b 6f 62 6a 65 63 74 7d |c}{repr}|{object}|
|000044c0| 0d 52 65 74 75 72 6e 20 | 61 20 73 74 72 69 6e 67 |.Return |a string|
|000044d0| 20 63 6f 6e 74 61 69 6e | 69 6e 67 20 61 20 70 72 | contain|ing a pr|
|000044e0| 69 6e 74 61 62 6c 65 20 | 72 65 70 72 65 73 65 6e |intable |represen|
|000044f0| 74 61 74 69 6f 6e 20 6f | 66 20 61 6e 20 6f 62 6a |tation o|f an obj|
|00004500| 65 63 74 2e 0d 54 68 69 | 73 20 69 73 20 74 68 65 |ect..Thi|s is the|
|00004510| 20 73 61 6d 65 20 76 61 | 6c 75 65 20 79 69 65 6c | same va|lue yiel|
|00004520| 64 65 64 20 62 79 20 63 | 6f 6e 76 65 72 73 69 6f |ded by c|onversio|
|00004530| 6e 73 20 28 72 65 76 65 | 72 73 65 20 71 75 6f 74 |ns (reve|rse quot|
|00004540| 65 73 29 2e 0d 49 74 20 | 69 73 20 73 6f 6d 65 74 |es)..It |is somet|
|00004550| 69 6d 65 73 20 75 73 65 | 66 75 6c 20 74 6f 20 62 |imes use|ful to b|
|00004560| 65 20 61 62 6c 65 20 74 | 6f 20 61 63 63 65 73 73 |e able t|o access|
|00004570| 20 74 68 69 73 20 6f 70 | 65 72 61 74 69 6f 6e 20 | this op|eration |
|00004580| 61 73 20 61 6e 0d 6f 72 | 64 69 6e 61 72 79 20 66 |as an.or|dinary f|
|00004590| 75 6e 63 74 69 6f 6e 2e | 20 20 46 6f 72 20 6d 61 |unction.| For ma|
|000045a0| 6e 79 20 74 79 70 65 73 | 2c 20 74 68 69 73 20 66 |ny types|, this f|
|000045b0| 75 6e 63 74 69 6f 6e 20 | 6d 61 6b 65 73 20 61 6e |unction |makes an|
|000045c0| 20 61 74 74 65 6d 70 74 | 0d 74 6f 20 72 65 74 75 | attempt|.to retu|
|000045d0| 72 6e 20 61 20 73 74 72 | 69 6e 67 20 74 68 61 74 |rn a str|ing that|
|000045e0| 20 77 6f 75 6c 64 20 79 | 69 65 6c 64 20 61 6e 20 | would y|ield an |
|000045f0| 6f 62 6a 65 63 74 20 77 | 69 74 68 20 74 68 65 20 |object w|ith the |
|00004600| 73 61 6d 65 20 76 61 6c | 75 65 0d 77 68 65 6e 20 |same val|ue.when |
|00004610| 70 61 73 73 65 64 20 74 | 6f 20 5c 63 6f 64 65 7b |passed t|o \code{|
|00004620| 65 76 61 6c 28 29 7d 2e | 0d 5c 65 6e 64 7b 66 75 |eval()}.|.\end{fu|
|00004630| 6e 63 64 65 73 63 7d 0d | 0d 5c 62 65 67 69 6e 7b |ncdesc}.|.\begin{|
|00004640| 66 75 6e 63 64 65 73 63 | 7d 7b 72 6f 75 6e 64 7d |funcdesc|}{round}|
|00004650| 7b 78 5c 2c 20 6e 7d 0d | 20 20 52 65 74 75 72 6e |{x\, n}.| Return|
|00004660| 20 74 68 65 20 66 6c 6f | 61 74 69 6e 67 20 70 6f | the flo|ating po|
|00004670| 69 6e 74 20 76 61 6c 75 | 65 20 5c 76 61 72 7b 78 |int valu|e \var{x|
|00004680| 7d 20 72 6f 75 6e 64 65 | 64 20 74 6f 20 5c 76 61 |} rounde|d to \va|
|00004690| 72 7b 6e 7d 20 64 69 67 | 69 74 73 0d 20 20 61 66 |r{n} dig|its. af|
|000046a0| 74 65 72 20 74 68 65 20 | 64 65 63 69 6d 61 6c 20 |ter the |decimal |
|000046b0| 70 6f 69 6e 74 2e 20 20 | 49 66 20 5c 76 61 72 7b |point. |If \var{|
|000046c0| 6e 7d 20 69 73 20 6f 6d | 69 74 74 65 64 2c 20 69 |n} is om|itted, i|
|000046d0| 74 20 64 65 66 61 75 6c | 74 73 20 74 6f 20 7a 65 |t defaul|ts to ze|
|000046e0| 72 6f 2e 0d 20 20 54 68 | 65 20 72 65 73 75 6c 74 |ro.. Th|e result|
|000046f0| 20 69 73 20 61 20 66 6c | 6f 61 74 69 6e 67 20 70 | is a fl|oating p|
|00004700| 6f 69 6e 74 20 6e 75 6d | 62 65 72 2e 20 20 56 61 |oint num|ber. Va|
|00004710| 6c 75 65 73 20 61 72 65 | 20 72 6f 75 6e 64 65 64 |lues are| rounded|
|00004720| 20 74 6f 20 74 68 65 0d | 20 20 63 6c 6f 73 65 73 | to the.| closes|
|00004730| 74 20 6d 75 6c 74 69 70 | 6c 65 20 6f 66 20 31 30 |t multip|le of 10|
|00004740| 20 74 6f 20 74 68 65 20 | 70 6f 77 65 72 20 6d 69 | to the |power mi|
|00004750| 6e 75 73 20 5c 76 61 72 | 7b 6e 7d 3b 20 69 66 20 |nus \var|{n}; if |
|00004760| 74 77 6f 20 6d 75 6c 74 | 69 70 6c 65 73 0d 20 20 |two mult|iples. |
|00004770| 61 72 65 20 65 71 75 61 | 6c 6c 79 20 63 6c 6f 73 |are equa|lly clos|
|00004780| 65 2c 20 72 6f 75 6e 64 | 69 6e 67 20 69 73 20 64 |e, round|ing is d|
|00004790| 6f 6e 65 20 61 77 61 79 | 20 66 72 6f 6d 20 30 20 |one away| from 0 |
|000047a0| 28 73 6f 20 65 2e 67 2e | 0d 20 20 5c 63 6f 64 65 |(so e.g.|. \code|
|000047b0| 7b 72 6f 75 6e 64 28 30 | 2e 35 29 7d 20 69 73 20 |{round(0|.5)} is |
|000047c0| 5c 63 6f 64 65 7b 31 2e | 30 7d 20 61 6e 64 20 5c |\code{1.|0} and \|
|000047d0| 63 6f 64 65 7b 72 6f 75 | 6e 64 28 2d 30 2e 35 29 |code{rou|nd(-0.5)|
|000047e0| 7d 20 69 73 20 5c 63 6f | 64 65 7b 2d 31 2e 30 7d |} is \co|de{-1.0}|
|000047f0| 29 2e 0d 5c 65 6e 64 7b | 66 75 6e 63 64 65 73 63 |)..\end{|funcdesc|
|00004800| 7d 0d 0d 5c 62 65 67 69 | 6e 7b 66 75 6e 63 64 65 |}..\begi|n{funcde|
|00004810| 73 63 7d 7b 73 65 74 61 | 74 74 72 7d 7b 6f 62 6a |sc}{seta|ttr}{obj|
|00004820| 65 63 74 5c 2c 20 6e 61 | 6d 65 5c 2c 20 76 61 6c |ect\, na|me\, val|
|00004830| 75 65 7d 0d 20 20 54 68 | 69 73 20 69 73 20 74 68 |ue}. Th|is is th|
|00004840| 65 20 63 6f 75 6e 74 65 | 72 70 61 72 74 20 6f 66 |e counte|rpart of|
|00004850| 20 5c 63 6f 64 65 7b 67 | 65 74 61 74 74 72 7d 2e | \code{g|etattr}.|
|00004860| 20 20 54 68 65 20 61 72 | 67 75 6d 65 6e 74 73 20 | The ar|guments |
|00004870| 61 72 65 20 61 6e 0d 20 | 20 6f 62 6a 65 63 74 2c |are an. | object,|
|00004880| 20 61 20 73 74 72 69 6e | 67 20 61 6e 64 20 61 6e | a strin|g and an|
|00004890| 20 61 72 62 69 74 72 61 | 72 79 20 76 61 6c 75 65 | arbitra|ry value|
|000048a0| 2e 20 20 54 68 65 20 73 | 74 72 69 6e 67 20 6d 75 |. The s|tring mu|
|000048b0| 73 74 20 62 65 20 74 68 | 65 20 6e 61 6d 65 0d 20 |st be th|e name. |
|000048c0| 20 6f 66 20 6f 6e 65 20 | 6f 66 20 74 68 65 20 6f | of one |of the o|
|000048d0| 62 6a 65 63 74 27 73 20 | 61 74 74 72 69 62 75 74 |bject's |attribut|
|000048e0| 65 73 2e 20 20 54 68 65 | 20 66 75 6e 63 74 69 6f |es. The| functio|
|000048f0| 6e 20 61 73 73 69 67 6e | 73 20 74 68 65 20 76 61 |n assign|s the va|
|00004900| 6c 75 65 20 74 6f 0d 20 | 20 74 68 65 20 61 74 74 |lue to. | the att|
|00004910| 72 69 62 75 74 65 2c 20 | 70 72 6f 76 69 64 65 64 |ribute, |provided|
|00004920| 20 74 68 65 20 6f 62 6a | 65 63 74 20 61 6c 6c 6f | the obj|ect allo|
|00004930| 77 73 20 69 74 2e 20 20 | 46 6f 72 20 65 78 61 6d |ws it. |For exam|
|00004940| 70 6c 65 2c 0d 20 20 5c | 63 6f 64 65 7b 73 65 74 |ple,. \|code{set|
|00004950| 61 74 74 72 28 5c 76 61 | 72 7b 78 7d 2c 20 27 5c |attr(\va|r{x}, '\|
|00004960| 76 61 72 7b 66 6f 6f 62 | 61 72 7d 27 2c 20 31 32 |var{foob|ar}', 12|
|00004970| 33 29 7d 20 69 73 20 65 | 71 75 69 76 61 6c 65 6e |3)} is e|quivalen|
|00004980| 74 20 74 6f 0d 20 20 5c | 63 6f 64 65 7b 5c 76 61 |t to. \|code{\va|
|00004990| 72 7b 78 7d 2e 5c 76 61 | 72 7b 66 6f 6f 62 61 72 |r{x}.\va|r{foobar|
|000049a0| 7d 20 3d 20 31 32 33 7d | 2e 0d 5c 65 6e 64 7b 66 |} = 123}|..\end{f|
|000049b0| 75 6e 63 64 65 73 63 7d | 0d 0d 5c 62 65 67 69 6e |uncdesc}|..\begin|
|000049c0| 7b 66 75 6e 63 64 65 73 | 63 7d 7b 73 74 72 7d 7b |{funcdes|c}{str}{|
|000049d0| 6f 62 6a 65 63 74 7d 0d | 52 65 74 75 72 6e 20 61 |object}.|Return a|
|000049e0| 20 73 74 72 69 6e 67 20 | 63 6f 6e 74 61 69 6e 69 | string |containi|
|000049f0| 6e 67 20 61 20 6e 69 63 | 65 6c 79 20 70 72 69 6e |ng a nic|ely prin|
|00004a00| 74 61 62 6c 65 20 72 65 | 70 72 65 73 65 6e 74 61 |table re|presenta|
|00004a10| 74 69 6f 6e 20 6f 66 20 | 61 6e 0d 6f 62 6a 65 63 |tion of |an.objec|
|00004a20| 74 2e 20 20 46 6f 72 20 | 73 74 72 69 6e 67 73 2c |t. For |strings,|
|00004a30| 20 74 68 69 73 20 72 65 | 74 75 72 6e 73 20 74 68 | this re|turns th|
|00004a40| 65 20 73 74 72 69 6e 67 | 20 69 74 73 65 6c 66 2e |e string| itself.|
|00004a50| 20 20 54 68 65 20 64 69 | 66 66 65 72 65 6e 63 65 | The di|fference|
|00004a60| 0d 77 69 74 68 20 5c 63 | 6f 64 65 7b 72 65 70 72 |.with \c|ode{repr|
|00004a70| 28 5c 76 61 72 7b 6f 62 | 6a 65 63 74 7d 29 7d 20 |(\var{ob|ject})} |
|00004a80| 69 73 20 74 68 61 74 20 | 5c 63 6f 64 65 7b 73 74 |is that |\code{st|
|00004a90| 72 28 5c 76 61 72 7b 6f | 62 6a 65 63 74 7d 29 7d |r(\var{o|bject})}|
|00004aa0| 20 64 6f 65 73 20 6e 6f | 74 0d 61 6c 77 61 79 73 | does no|t.always|
|00004ab0| 20 61 74 74 65 6d 70 74 | 20 74 6f 20 72 65 74 75 | attempt| to retu|
|00004ac0| 72 6e 20 61 20 73 74 72 | 69 6e 67 20 74 68 61 74 |rn a str|ing that|
|00004ad0| 20 69 73 20 61 63 63 65 | 70 74 61 62 6c 65 20 74 | is acce|ptable t|
|00004ae0| 6f 20 5c 63 6f 64 65 7b | 65 76 61 6c 28 29 7d 3b |o \code{|eval()};|
|00004af0| 0d 69 74 73 20 67 6f 61 | 6c 20 69 73 20 74 6f 20 |.its goa|l is to |
|00004b00| 72 65 74 75 72 6e 20 61 | 20 70 72 69 6e 74 61 62 |return a| printab|
|00004b10| 6c 65 20 73 74 72 69 6e | 67 2e 0d 5c 65 6e 64 7b |le strin|g..\end{|
|00004b20| 66 75 6e 63 64 65 73 63 | 7d 0d 0d 5c 62 65 67 69 |funcdesc|}..\begi|
|00004b30| 6e 7b 66 75 6e 63 64 65 | 73 63 7d 7b 74 75 70 6c |n{funcde|sc}{tupl|
|00004b40| 65 7d 7b 73 65 71 75 65 | 6e 63 65 7d 0d 52 65 74 |e}{seque|nce}.Ret|
|00004b50| 75 72 6e 20 61 20 74 75 | 70 6c 65 20 77 68 6f 73 |urn a tu|ple whos|
|00004b60| 65 20 69 74 65 6d 73 20 | 61 72 65 20 74 68 65 20 |e items |are the |
|00004b70| 73 61 6d 65 20 61 6e 64 | 20 69 6e 20 74 68 65 20 |same and| in the |
|00004b80| 73 61 6d 65 20 6f 72 64 | 65 72 20 61 73 0d 5c 76 |same ord|er as.\v|
|00004b90| 61 72 7b 73 65 71 75 65 | 6e 63 65 7d 27 73 20 69 |ar{seque|nce}'s i|
|00004ba0| 74 65 6d 73 2e 20 20 49 | 66 20 5c 76 61 72 7b 73 |tems. I|f \var{s|
|00004bb0| 65 71 75 65 6e 63 65 7d | 20 69 73 20 61 6c 72 65 |equence}| is alre|
|00004bc0| 61 64 20 61 20 74 75 70 | 6c 65 2c 20 69 74 0d 69 |ad a tup|le, it.i|
|00004bd0| 73 20 72 65 74 75 72 6e | 65 64 20 75 6e 63 68 61 |s return|ed uncha|
|00004be0| 6e 67 65 64 2e 20 20 46 | 6f 72 20 69 6e 73 74 61 |nged. F|or insta|
|00004bf0| 6e 63 65 2c 20 5c 63 6f | 64 65 7b 74 75 70 6c 65 |nce, \co|de{tuple|
|00004c00| 28 27 61 62 63 27 29 7d | 20 72 65 74 75 72 6e 73 |('abc')}| returns|
|00004c10| 0d 72 65 74 75 72 6e 73 | 20 5c 63 6f 64 65 7b 28 |.returns| \code{(|
|00004c20| 27 61 27 2c 20 27 62 27 | 2c 20 27 63 27 29 7d 20 |'a', 'b'|, 'c')} |
|00004c30| 61 6e 64 20 5c 63 6f 64 | 65 7b 74 75 70 6c 65 28 |and \cod|e{tuple(|
|00004c40| 5b 31 2c 20 32 2c 20 33 | 5d 29 7d 20 72 65 74 75 |[1, 2, 3|])} retu|
|00004c50| 72 6e 73 0d 5c 63 6f 64 | 65 7b 28 31 2c 20 32 2c |rns.\cod|e{(1, 2,|
|00004c60| 20 33 29 7d 2e 0d 5c 65 | 6e 64 7b 66 75 6e 63 64 | 3)}..\e|nd{funcd|
|00004c70| 65 73 63 7d 0d 0d 5c 62 | 65 67 69 6e 7b 66 75 6e |esc}..\b|egin{fun|
|00004c80| 63 64 65 73 63 7d 7b 74 | 79 70 65 7d 7b 6f 62 6a |cdesc}{t|ype}{obj|
|00004c90| 65 63 74 7d 0d 52 65 74 | 75 72 6e 20 74 68 65 20 |ect}.Ret|urn the |
|00004ca0| 74 79 70 65 20 6f 66 20 | 61 6e 20 5c 76 61 72 7b |type of |an \var{|
|00004cb0| 6f 62 6a 65 63 74 7d 2e | 20 20 54 68 65 20 72 65 |object}.| The re|
|00004cc0| 74 75 72 6e 20 76 61 6c | 75 65 20 69 73 20 61 20 |turn val|ue is a |
|00004cd0| 74 79 70 65 0d 6f 62 6a | 65 63 74 2e 20 20 54 68 |type.obj|ect. Th|
|00004ce0| 65 20 73 74 61 6e 64 61 | 72 64 20 6d 6f 64 75 6c |e standa|rd modul|
|00004cf0| 65 20 5c 63 6f 64 65 7b | 74 79 70 65 73 7d 20 64 |e \code{|types} d|
|00004d00| 65 66 69 6e 65 73 20 6e | 61 6d 65 73 20 66 6f 72 |efines n|ames for|
|00004d10| 20 61 6c 6c 0d 62 75 69 | 6c 74 2d 69 6e 20 74 79 | all.bui|lt-in ty|
|00004d20| 70 65 73 2e 0d 5c 73 74 | 6d 6f 64 69 6e 64 65 78 |pes..\st|modindex|
|00004d30| 7b 74 79 70 65 73 7d 0d | 5c 6f 62 69 6e 64 65 78 |{types}.|\obindex|
|00004d40| 7b 74 79 70 65 7d 0d 46 | 6f 72 20 69 6e 73 74 61 |{type}.F|or insta|
|00004d50| 6e 63 65 3a 0d 0d 5c 62 | 63 6f 64 65 5c 62 65 67 |nce:..\b|code\beg|
|00004d60| 69 6e 7b 76 65 72 62 61 | 74 69 6d 7d 0d 3e 3e 3e |in{verba|tim}.>>>|
|00004d70| 20 69 6d 70 6f 72 74 20 | 74 79 70 65 73 0d 3e 3e | import |types.>>|
|00004d80| 3e 20 69 66 20 74 79 70 | 65 28 78 29 20 3d 3d 20 |> if typ|e(x) == |
|00004d90| 74 79 70 65 73 2e 53 74 | 72 69 6e 67 54 79 70 65 |types.St|ringType|
|00004da0| 3a 20 70 72 69 6e 74 20 | 22 49 74 27 73 20 61 20 |: print |"It's a |
|00004db0| 73 74 72 69 6e 67 22 0d | 5c 65 6e 64 7b 76 65 72 |string".|\end{ver|
|00004dc0| 62 61 74 69 6d 7d 5c 65 | 63 6f 64 65 0d 5c 65 6e |batim}\e|code.\en|
|00004dd0| 64 7b 66 75 6e 63 64 65 | 73 63 7d 0d 0d 5c 62 65 |d{funcde|sc}..\be|
|00004de0| 67 69 6e 7b 66 75 6e 63 | 64 65 73 63 7d 7b 76 61 |gin{func|desc}{va|
|00004df0| 72 73 7d 7b 5c 6f 70 74 | 69 6f 6e 61 6c 7b 6f 62 |rs}{\opt|ional{ob|
|00004e00| 6a 65 63 74 7d 7d 0d 57 | 69 74 68 6f 75 74 20 61 |ject}}.W|ithout a|
|00004e10| 72 67 75 6d 65 6e 74 73 | 2c 20 72 65 74 75 72 6e |rguments|, return|
|00004e20| 20 61 20 64 69 63 74 69 | 6f 6e 61 72 79 20 63 6f | a dicti|onary co|
|00004e30| 72 72 65 73 70 6f 6e 64 | 69 6e 67 20 74 6f 20 74 |rrespond|ing to t|
|00004e40| 68 65 20 63 75 72 72 65 | 6e 74 0d 6c 6f 63 61 6c |he curre|nt.local|
|00004e50| 20 73 79 6d 62 6f 6c 20 | 74 61 62 6c 65 2e 20 20 | symbol |table. |
|00004e60| 57 69 74 68 20 61 20 6d | 6f 64 75 6c 65 2c 20 63 |With a m|odule, c|
|00004e70| 6c 61 73 73 20 6f 72 20 | 63 6c 61 73 73 20 69 6e |lass or |class in|
|00004e80| 73 74 61 6e 63 65 20 6f | 62 6a 65 63 74 20 61 73 |stance o|bject as|
|00004e90| 0d 61 72 67 75 6d 65 6e | 74 20 28 6f 72 20 61 6e |.argumen|t (or an|
|00004ea0| 79 74 68 69 6e 67 20 65 | 6c 73 65 20 74 68 61 74 |ything e|lse that|
|00004eb0| 20 68 61 73 20 61 20 5c | 63 6f 64 65 7b 5f 5f 64 | has a \|code{__d|
|00004ec0| 69 63 74 5f 5f 7d 20 61 | 74 74 72 69 62 75 74 65 |ict__} a|ttribute|
|00004ed0| 29 2c 0d 72 65 74 75 72 | 6e 73 20 61 20 64 69 63 |),.retur|ns a dic|
|00004ee0| 74 69 6f 6e 61 72 79 20 | 63 6f 72 72 65 73 70 6f |tionary |correspo|
|00004ef0| 6e 64 69 6e 67 20 74 6f | 20 74 68 65 20 6f 62 6a |nding to| the obj|
|00004f00| 65 63 74 27 73 20 73 79 | 6d 62 6f 6c 20 74 61 62 |ect's sy|mbol tab|
|00004f10| 6c 65 2e 0d 54 68 65 20 | 72 65 74 75 72 6e 65 64 |le..The |returned|
|00004f20| 20 64 69 63 74 69 6f 6e | 61 72 79 20 73 68 6f 75 | diction|ary shou|
|00004f30| 6c 64 20 6e 6f 74 20 62 | 65 20 6d 6f 64 69 66 69 |ld not b|e modifi|
|00004f40| 65 64 3a 20 74 68 65 20 | 65 66 66 65 63 74 73 20 |ed: the |effects |
|00004f50| 6f 6e 20 74 68 65 0d 63 | 6f 72 72 65 73 70 6f 6e |on the.c|orrespon|
|00004f60| 64 69 6e 67 20 73 79 6d | 62 6f 6c 20 74 61 62 6c |ding sym|bol tabl|
|00004f70| 65 20 61 72 65 20 75 6e | 64 65 66 69 6e 65 64 2e |e are un|defined.|
|00004f80| 25 0d 5c 66 6f 6f 74 6e | 6f 74 65 7b 49 6e 20 74 |%.\footn|ote{In t|
|00004f90| 68 65 20 63 75 72 72 65 | 6e 74 20 69 6d 70 6c 65 |he curre|nt imple|
|00004fa0| 6d 65 6e 74 61 74 69 6f | 6e 2c 20 6c 6f 63 61 6c |mentatio|n, local|
|00004fb0| 20 76 61 72 69 61 62 6c | 65 20 62 69 6e 64 69 6e | variabl|e bindin|
|00004fc0| 67 73 0d 63 61 6e 6e 6f | 74 20 6e 6f 72 6d 61 6c |gs.canno|t normal|
|00004fd0| 6c 79 20 62 65 20 61 66 | 66 65 63 74 65 64 20 74 |ly be af|fected t|
|00004fe0| 68 69 73 20 77 61 79 2c | 20 62 75 74 20 76 61 72 |his way,| but var|
|00004ff0| 69 61 62 6c 65 73 20 72 | 65 74 72 69 65 76 65 64 |iables r|etrieved|
|00005000| 20 66 72 6f 6d 0d 6f 74 | 68 65 72 20 73 63 6f 70 | from.ot|her scop|
|00005010| 65 73 20 28 65 2e 67 2e | 20 6d 6f 64 75 6c 65 73 |es (e.g.| modules|
|00005020| 29 20 63 61 6e 20 62 65 | 2e 20 20 54 68 69 73 20 |) can be|. This |
|00005030| 6d 61 79 20 63 68 61 6e | 67 65 2e 7d 0d 5c 65 6e |may chan|ge.}.\en|
|00005040| 64 7b 66 75 6e 63 64 65 | 73 63 7d 0d 0d 5c 62 65 |d{funcde|sc}..\be|
|00005050| 67 69 6e 7b 66 75 6e 63 | 64 65 73 63 7d 7b 78 72 |gin{func|desc}{xr|
|00005060| 61 6e 67 65 7d 7b 5c 6f | 70 74 69 6f 6e 61 6c 7b |ange}{\o|ptional{|
|00005070| 73 74 61 72 74 5c 2c 7d | 20 65 6e 64 5c 6f 70 74 |start\,}| end\opt|
|00005080| 69 6f 6e 61 6c 7b 5c 2c | 20 73 74 65 70 7d 7d 0d |ional{\,| step}}.|
|00005090| 54 68 69 73 20 66 75 6e | 63 74 69 6f 6e 20 69 73 |This fun|ction is|
|000050a0| 20 76 65 72 79 20 73 69 | 6d 69 6c 61 72 20 74 6f | very si|milar to|
|000050b0| 20 5c 63 6f 64 65 7b 72 | 61 6e 67 65 28 29 7d 2c | \code{r|ange()},|
|000050c0| 20 62 75 74 20 72 65 74 | 75 72 6e 73 20 61 6e 0d | but ret|urns an.|
|000050d0| 60 60 78 72 61 6e 67 65 | 20 6f 62 6a 65 63 74 27 |``xrange| object'|
|000050e0| 27 20 69 6e 73 74 65 61 | 64 20 6f 66 20 61 20 6c |' instea|d of a l|
|000050f0| 69 73 74 2e 20 20 54 68 | 69 73 20 69 73 20 61 6e |ist. Th|is is an|
|00005100| 20 6f 70 61 71 75 65 20 | 73 65 71 75 65 6e 63 65 | opaque |sequence|
|00005110| 20 74 79 70 65 0d 77 68 | 69 63 68 20 79 69 65 6c | type.wh|ich yiel|
|00005120| 64 73 20 74 68 65 20 73 | 61 6d 65 20 76 61 6c 75 |ds the s|ame valu|
|00005130| 65 73 20 61 73 20 74 68 | 65 20 63 6f 72 72 65 73 |es as th|e corres|
|00005140| 70 6f 6e 64 69 6e 67 20 | 6c 69 73 74 2c 20 77 69 |ponding |list, wi|
|00005150| 74 68 6f 75 74 0d 61 63 | 74 75 61 6c 6c 79 20 73 |thout.ac|tually s|
|00005160| 74 6f 72 69 6e 67 20 74 | 68 65 6d 20 61 6c 6c 20 |toring t|hem all |
|00005170| 73 69 6d 75 6c 74 61 6e | 65 6f 75 73 6c 79 2e 20 |simultan|eously. |
|00005180| 20 54 68 65 20 61 64 76 | 61 6e 74 61 67 65 20 6f | The adv|antage o|
|00005190| 66 0d 5c 63 6f 64 65 7b | 78 72 61 6e 67 65 28 29 |f.\code{|xrange()|
|000051a0| 7d 20 6f 76 65 72 20 5c | 63 6f 64 65 7b 72 61 6e |} over \|code{ran|
|000051b0| 67 65 28 29 7d 20 69 73 | 20 6d 69 6e 69 6d 61 6c |ge()} is| minimal|
|000051c0| 20 28 73 69 6e 63 65 20 | 5c 63 6f 64 65 7b 78 72 | (since |\code{xr|
|000051d0| 61 6e 67 65 28 29 7d 0d | 73 74 69 6c 6c 20 68 61 |ange()}.|still ha|
|000051e0| 73 20 74 6f 20 63 72 65 | 61 74 65 20 74 68 65 20 |s to cre|ate the |
|000051f0| 76 61 6c 75 65 73 20 77 | 68 65 6e 20 61 73 6b 65 |values w|hen aske|
|00005200| 64 20 66 6f 72 20 74 68 | 65 6d 29 20 65 78 63 65 |d for th|em) exce|
|00005210| 70 74 20 77 68 65 6e 20 | 61 20 76 65 72 79 0d 6c |pt when |a very.l|
|00005220| 61 72 67 65 20 72 61 6e | 67 65 20 69 73 20 75 73 |arge ran|ge is us|
|00005230| 65 64 20 6f 6e 20 61 20 | 6d 65 6d 6f 72 79 2d 73 |ed on a |memory-s|
|00005240| 74 61 72 76 65 64 20 6d | 61 63 68 69 6e 65 20 28 |tarved m|achine (|
|00005250| 65 2e 67 2e 20 4d 53 2d | 44 4f 53 29 20 6f 72 20 |e.g. MS-|DOS) or |
|00005260| 77 68 65 6e 20 61 6c 6c | 0d 6f 66 20 74 68 65 20 |when all|.of the |
|00005270| 72 61 6e 67 65 27 73 20 | 65 6c 65 6d 65 6e 74 73 |range's |elements|
|00005280| 20 61 72 65 20 6e 65 76 | 65 72 20 75 73 65 64 20 | are nev|er used |
|00005290| 28 65 2e 67 2e 20 77 68 | 65 6e 20 74 68 65 20 6c |(e.g. wh|en the l|
|000052a0| 6f 6f 70 20 69 73 20 75 | 73 75 61 6c 6c 79 0d 74 |oop is u|sually.t|
|000052b0| 65 72 6d 69 6e 61 74 65 | 64 20 77 69 74 68 20 5c |erminate|d with \|
|000052c0| 63 6f 64 65 7b 62 72 65 | 61 6b 7d 29 2e 0d 5c 65 |code{bre|ak})..\e|
|000052d0| 6e 64 7b 66 75 6e 63 64 | 65 73 63 7d 0d |nd{funcd|esc}. |
+--------+-------------------------+-------------------------+--------+--------+